L ldg Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #1 VB调用Delphi编的dll,将string变量全部作为参数传给dll,处理完后<br>想取回修改后的变量值.但试过integer变量可以,string变量不行,不<br>知为什么?我在delphi里声明的是var类型的PChar参数.VB调用用默认方式<br>,没有用ByVal.<br><br>
VB调用Delphi编的dll,将string变量全部作为参数传给dll,处理完后<br>想取回修改后的变量值.但试过integer变量可以,string变量不行,不<br>知为什么?我在delphi里声明的是var类型的PChar参数.VB调用用默认方式<br>,没有用ByVal.<br><br>
C cytown Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #3 use ByRef and try again, if not changed, check the dll.<br>
L ldg Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #6 dll:<br>library sat2;<br><br>uses<br> SysUtils,<br> Classes;<br> function aaa(var str1Char):integer;stdcall<br><br> begin<br> str1:='abc';<br> end;<br>exports<br>aaa;<br>begin<br>end.<br> <br><br>VB中调用:<br><br>Private Declare Function aaa Lib "sat" (ByVal str2 As String) As Integer<br>Private Sub Command1_Click()<br>Dim sss As String<br>sss = "aaaa"<br>abc = aaa(sss)<br>MsgBox (sss)<br>End Sub<br><br><br>调用结果:变量sss仍为"aaaa",而没有变为"abc",且非法操作死机.<br>望指点.<br>
dll:<br>library sat2;<br><br>uses<br> SysUtils,<br> Classes;<br> function aaa(var str1Char):integer;stdcall<br><br> begin<br> str1:='abc';<br> end;<br>exports<br>aaa;<br>begin<br>end.<br> <br><br>VB中调用:<br><br>Private Declare Function aaa Lib "sat" (ByVal str2 As String) As Integer<br>Private Sub Command1_Click()<br>Dim sss As String<br>sss = "aaaa"<br>abc = aaa(sss)<br>MsgBox (sss)<br>End Sub<br><br><br>调用结果:变量sss仍为"aaaa",而没有变为"abc",且非法操作死机.<br>望指点.<br>
A Another_eYes Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #7 问题在此:<br> function aaa(var str1Char):integer;stdcall<br><br> begin<br> str1:='abc';<br> ^^^^^^^^^^^^<br> end;<br><br>改成strcopy(str1, pchar('abc'));<br>str1 := 'abc'替换了str1的地址, 所以非法操作.
问题在此:<br> function aaa(var str1Char):integer;stdcall<br><br> begin<br> str1:='abc';<br> ^^^^^^^^^^^^<br> end;<br><br>改成strcopy(str1, pchar('abc'));<br>str1 := 'abc'替换了str1的地址, 所以非法操作.
C cAkk Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #8 function aaa(var str1:<font color=red>String</font>:integer;stdcall<br>
L ldg Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #9 Another_eYes和cAkk的方法都行不通,运行时提示非法操作.
A Another_eYes Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #10 ???<br>难道vb的string型不是根据c++的类型而是和delphi的string型一样?<br>我怎么记得vb的string也是个#0结尾的字符串(delphi中的pchar)?
C cAkk Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #11 不可能. 我把你的代码拷贝下来,修改后直接运行,一切正常后才回答你问题的!<br>把DLL参数改成string肯定没问题!
C cAkk Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-09 #13 忘了说了:<br>Private Declare Function aaa Lib "sat" (<font color=red>ByVal</font> str2 As String) As Integer<br>把红字去掉!<br><br>我不是已经告诉你了吗? 不要用ByVal.<br>
忘了说了:<br>Private Declare Function aaa Lib "sat" (<font color=red>ByVal</font> str2 As String) As Integer<br>把红字去掉!<br><br>我不是已经告诉你了吗? 不要用ByVal.<br>
L ldg Unregistered / Unconfirmed GUEST, unregistred user! 1999-11-10 #14 我接受cAkk的答案,且Another_eYes <br>的答案如果在调用时把ByVal去掉也可以.
J job_fan Unregistered / Unconfirmed GUEST, unregistred user! 2002-03-07 #15 我刚做了一个这方面的例子,我用的方法和ANOTHER——EYES的相同,ByVal是必须要的,<br>如果不要的话,虽然也能取值,但都是错的,而且在其他处理后,再重复操作,取值都不<br>同了。