您正在使用一款已经过时的浏览器!部分功能不能正常使用。
请尝试升级或使用
其他浏览器。
请教一个DLL兼容性的问题??? 100分(100分)
rob
Unregistered / Unconfirmed
GUEST, unregistred user!
我用DELPHI写了一个非常简单的DLL做试验,让VB调用,<br>发现用除了PCHAR类型以外得所有类型做为传递参数在VB就能调用成功,可是一用PCHAR,<br>VB调用的时候老是关闭性错误!<br>请那位高人指点迷经(函数调用一定得有字符参数)<br>程序如下:<br>Delphi DLL<br>**********************************<br>library Project1;<br>uses<br> SysUtils,<br> Classes;<br><br>{$R *.res}<br>function robtest(VAR buf
char):integer;stdcall;<br> begin<br> buf:='rob';<br> result:=2003;<br> end;<br><br>exports<br> robtest;<br>begin<br>end.<br>*************************************************<br>VB 调用程序<br>Private Declare Function robtest Lib "c:/windows/desktop/dll/test/Project1.dll" (ByVal buf As String) As Long<br><br>Private Sub Command1_Click()<br>Dim a As Integer<br>Dim bb As String <br>a = robtest(bb)<br>Text1.Text = Text1.Text + bb + ";" + Str(a)<br>End Sub<br>**************************************************<br><br>
tseug
Unregistered / Unconfirmed
GUEST, unregistred user!
rob
Unregistered / Unconfirmed
GUEST, unregistred user!
问题自己已经解决了<br>是DELPHI中function里用Var 声明的参数,在VB调用里不能加Byval<br>delphi里给PCHAR参数赋值时用,用个string类型变量倒一下<br>修改后<br>elphi DLL<br>**********************************<br>library Project1;<br>uses<br> SysUtils,<br> Classes;<br><br>{$R *.res}<br>function robtest(VAR buf
char):integer;stdcall;<br>var<br>tempL:string;<br>begin<br> temp:='rob';<br> buf:=pchar(temp);<br> result:=2003;<br>end;<br><br>exports<br> robtest;<br>begin<br>end.<br>*************************************************<br>VB 调用程序<br>Private Declare Function robtest Lib "c:/windows/desktop/dll/test/Project1.dll" (buf As String) As Long<br><br>Private Sub Command1_Click()<br>Dim a As Integer<br>Dim bb As String <br>a = robtest(bb)<br>Text1.Text = Text1.Text + bb + ";" + Str(a)<br>End Sub<br>**************************************************<br>
wuya_99
Unregistered / Unconfirmed
GUEST, unregistred user!
wjh_wy
Unregistered / Unconfirmed
GUEST, unregistred user!