DLL接口函数定义问题 熟悉Delphi和VB的朋友请进(100分)

  • 主题发起人 followindy
  • 开始时间
tO<br>以下是VB中调用XOM_SEND, &nbsp;XCOM_RECV的例子。供大家参考<br>Private Sub sendBtn_Click()<br>&nbsp; &nbsp; Dim ret As Long<br>&nbsp; &nbsp; Dim sendbuff As String &nbsp; &nbsp;<br>&nbsp; &nbsp; Dim msgid As String<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; msgid = "z000"<br>&nbsp; &nbsp; sendbuff = String(50, "a")<br>&nbsp; &nbsp; ret = xcom_send(msgid, sendbuff, Len(sendbuff)) &nbsp; &nbsp;<br>&nbsp; &nbsp; If ret &lt;&gt; 0 Then<br>&nbsp; &nbsp; &nbsp; &nbsp; MsgBox CStr(ret)<br>&nbsp; &nbsp; End If<br>End Sub<br><br>Private Sub recvBtn_Click()<br>&nbsp; &nbsp; Dim ret As Long<br>&nbsp; &nbsp; Dim recvbuff As String &nbsp; &nbsp;<br>&nbsp; &nbsp; Dim msgid As String<br>&nbsp; &nbsp; Dim BorF As Long<br>&nbsp; &nbsp; Dim recvlength As Long<br>&nbsp; &nbsp; recvbuff = Space(4096)<br>&nbsp; &nbsp; msgid = Space(32) <br>&nbsp; &nbsp; ret = xcom_recv(55, recvbuff, 4096, msgid, recvlength, BorF) &nbsp; &nbsp;<br>&nbsp; &nbsp; recvbuff = RTrim(recvbuff)<br>&nbsp; &nbsp; msgid = RTrim(msgid)<br>&nbsp; &nbsp; MsgBox (msgid) &nbsp; <br>&nbsp; &nbsp; <br>&nbsp; &nbsp; If recvlength = Len(recvbuff) Then<br>&nbsp; &nbsp; &nbsp; &nbsp; MsgBox (recvbuff)<br>&nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; MsgBox CStr(ret)<br>&nbsp; &nbsp; End If<br>End Sub<br><br>请大家帮忙 &nbsp;分我会再加
 
TO yyanghhong:你的方法我试过了。无效。<br>To &nbsp;zjan521:谢谢你的指正<br><br>我贴出了VB调用实例。请教各位。
 
如果你愿意的话,可以把Dll发给我,我帮你试试.heavenghost2k@hotmail.com
 
To &nbsp;proman<br><br>VBDLL.dll以及VB样例程序已经寄出。请查收。<br>谢谢。
 
TO followindy<br>没有收到啊!你的附件有多大啊.<br>再从发一遍吧.
 
我到现在还没有自己写过dll,不知哪位大哥有点资料的话,妹点给我:<br>planetike@sohu.com<br>谢了,开帖给分。
 
To Proman:<br><br>已再次mail。谢谢帮忙。
 
注意一下调用方式,试试cdecl方式
 
To Followindy <br>你的附件有多大啊,我还是没收到啊.你把你邮箱留给我.
 
followindy@163.com<br><br>才180多K啊
 
晕啊!!DELPHI的function中如果变量是由DLL返回的前面必须加var保留字,<br>不然就会出错!VB和VC++中就不需要了。还有如果DLL返回的string是以0号ASCII字符结尾的<br>(也就是DELPHI中的Char类型)那你就要用char去对应,不能用delphi的string去对应!<br>你可以自己定义一个char的数组类型,如<br>type<br>&nbsp; &nbsp;viChar = array[0..255]of char;<br>
 
看看VB这里的定义:ByVal nChannelId As Long<br>Delphi里应该这样写 var nChannelID: LongInt;<br>或者是 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hChannelID: PLongInt;<br><br>至于VB这样的定义:ByVal pMessageId As String<br>在Delphi可以这样写: pMessageID: PChar;<br>使用: AStr:=StrPas(pMessageID);
 
抱歉各位。我的接口定义方式问题不大,<br>调试异常是因为上述3个函数调用必须有先后顺序。<br>多谢大家。<br><br>谢谢zjan521指出var问题<br>谢谢proman的热心帮助
 
有没搞错,这是倒分吗?
 
不是。 &nbsp;因為這個Dll是別人做的中間件產品。我不熟悉用法,所以引發如題問題。<br>再次謝謝proman
 
顶部