语法级别的弱问题:如何声明DLL函数? 50分奉送(50分)

  • 主题发起人 主题发起人 ArnoldH
  • 开始时间 开始时间
A

ArnoldH

Unregistered / Unconfirmed
GUEST, unregistred user!
&nbsp; 首先声明:我对Delphi不熟。<br>&nbsp; &nbsp;有这样的一个外部函数,需要传递2个字符传进去,其中后者需要作为加密结果返回,<br>无论我怎样声明,在调用时总是报错,不知哪位大侠可以指点迷津? &nbsp; <br>//Function MakeMD5Digest(var as_Data : PChar; var as_Digest : Array of Char) : LongWord; stdcall;<br>//Function MakeMD5Digest(var as_Data : PChar; var as_Digest : Array of Char) : LongWord;<br>Function MakeMD5Digest(var as_Data : PChar; var as_Digest : PChar) : LongWord; stdcall;<br>......<br>Function MakeMD5Digest; external 'MD5DLL.dll' name 'MakeMD5Digest';<br><br><br>调用时:<br><br>变量:<br>&nbsp; &nbsp;larrchar_MD5Password : array[0..32 - 1] of Char;<br>&nbsp; &nbsp;lpchar_MD5Password : PChar;<br>&nbsp; &nbsp;lpchar_UserPassword : PChar;<br>&nbsp; &nbsp;ls_MD5Password : string;<br><br>语句:<br>&nbsp; &nbsp;lpchar_UserPassword := 'acx';<br>&nbsp; &nbsp;lpchar_UserPassword := PChar(as_UserPassword);<br>&nbsp; &nbsp;lpchar_MD5Password := ' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;';<br>&nbsp; &nbsp;MakeMD5Digest(lpchar_UserPassword,lpchar_MD5Password);<br>&nbsp; &nbsp;<br>&nbsp; 在不同的声明方式下,要么提示错误,要么返回'',让我哭笑不得。该动态连接库我已经<br>在VB和PB下调用成功。<br>&nbsp; 到底错在哪里?
 
聲明這樣試試:<br>1.Function MakeMD5Digest(as_Data : PChar; var as_Digest : PChar) : LongWord; stdcall;<br>external 'MD5DLL.dll' name 'MakeMD5Digest';<br>去掉前面一個的Var.<br>2.Function MakeMD5Digest(as_Data : PChar; var as_Digest : PChar) : LongWord; pascal;<br>external 'MD5DLL.dll';<br><br>
 
不想要分!!!<br>
 
請給在VB中的宣告
 
&nbsp; to zxb200:<br>&nbsp; &nbsp; &nbsp; 将第一个var去掉了也不行。<br><br>&nbsp; &nbsp;to lorderic:<br>&nbsp; &nbsp; &nbsp;VB下的声明如下:<br>&nbsp; &nbsp; &nbsp;Private Declare Function MakeMD5Digest Lib "di_MD5DLL.dll" (ByVal sData As String, ByVal sDigest As String) As Long<br>
 
你在宣告時將兩個參數的Var都去掉<br><br>MakeMD5Digest(as_Data : PChar; as_Digest : PChar) : LongWord; stdcall;<br><br>在呼叫時as_Data要指向來源字串, 而as_Digest必需指向存放傳回結果的 Buffer<br>要確認的是在呼叫時, 要確保傳入的Buffer空間要足夠,因為依Windows API的慣<br>例, 如果要以傳入Buffer位置來存放傳回值, 通常還會有另一個參數傳入Buffer<br>的大小, 函式中依此判斷如果要填入的值, 比Buffer還大, 就會傳回錯誤碼。<br>但此函數並沒有, 顯示函式中是不管的, 如果傳入的Buffer的太小, ....<br>建議, 最好Buffer給大一些<br><br>var<br>&nbsp; &nbsp;S: string;<br>&nbsp; &nbsp;DataBuf: array[0..255] of Char;<br>begin<br>&nbsp; &nbsp;S := 'Test';<br>&nbsp; &nbsp;MakeMD5Digest(PChar(S), DataBuf);<br>end;<br><br>
 
对,应先给PChar分配空间,如lorderic
 
to lorderic:<br>&nbsp; &nbsp; 不愧是高手高手高高手,你提供的办法我尝试过,可惜在声明时仍然带着var。现在已经<br>解决,多谢!<br><br>&nbsp;to zxb:<br>&nbsp; &nbsp; 虽然你没有给出正确答案,但是已经接近,特此奉献5分(没办法,谁让我是穷人呢),<br>请笑纳。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
568
import
I
后退
顶部