急急,如何将调用DLL的DELPHI代码转成VB代码(200分)

  • 主题发起人 主题发起人 ywan
  • 开始时间 开始时间
Y

ywan

Unregistered / Unconfirmed
GUEST, unregistred user!
各位好<br>&nbsp; 下面是一段DELPHI调用DLL的代码,不知如何将它转成VB的代码(关键是指针函数如何转换),小弟急用,谢谢!<br>type TDeliver = procedure(deliver: DeliverStr);<br>type TReport &nbsp;= procedure(Report: ReportStr);<br><br>{$R *.DFM}<br><br>function StartUp(cLocalIp: pchar; iLocalPort: integer; deliver: TDeliver; report: TReport; bb,cc: pointer): integer;stdcall;external 'Startup.DLL' name 'Startup';
 
Declare Function StartUp Lib "Startup.dll" Alias "AddFontResourceA"(cLocalIp as string, iLocalPort as Long, deliver as &nbsp;Long, report as Long, bb as Long, cc as Long) as Long<br>private sub TDeliver(deliver as DeliverStr) '这个参数类型要自己定义<br>&nbsp; &nbsp; '这是回调函数<br>end sub<br><br>private sub TReport(Report as ReportStr) &nbsp; '这个参数类型要自己定义<br>&nbsp; &nbsp; '这是回调函数<br>end sub<br><br>现个函数参数调用时以&amp;TDeliver的方式使用<br>
 
谢谢kkyy:<br>&nbsp; &nbsp;请问<br>&nbsp; &nbsp;private sub TDeliver(deliver as DeliverStr) '这个参数类型要自己定义<br>&nbsp; &nbsp; '这是回调函数<br>&nbsp; end sub<br><br>&nbsp; private sub TReport(Report as ReportStr) &nbsp; '这个参数类型要自己定义<br>&nbsp; &nbsp; &nbsp;'这是回调函数<br>&nbsp; end sub<br>&nbsp; 是不是<br>&nbsp; Declare Function StartUp Lib "Startup.dll" Alias "AddFontResourceA"(cLocalIp as string, iLocalPort as Long, deliver as &nbsp;Long, report as Long, bb as Long, cc as Long) as Long<br>里面的所指deliver、report两个函数 ?如果是,那函数名是不是要相同?<br><br>&nbsp;现个函数参数调用时以&amp;TDeliver的方式使用 &nbsp;是什么意思?<br>&nbsp; 小弟不甚明白,还恳请大哥详说,麻烦了,谢谢!<br><br><br>
 
函数名随便定<br>取函数的地址, 也可以用ADDR函数取地址
 
to kkyy:<br><br>请问在调用StartUp函数时,下面一段代码是否正确?<br>x = testbas.StartUp(cLocalIp, AddressOf testbas.Deliver, AddressOf testbas.Report, AddressOf testbas.Response, AddressOf testbas.MTError)<br><br>Function Deliver(FDeliver As String) As Long<br>&nbsp; &nbsp; 。。。。。。。。。。。。。<br>&nbsp; &nbsp; Deliver = 1<br>End Function<br><br><br>好象听说VB的指针函数一定要在通用模块(.bas)里定义,请问是否有这回事?<br>谢谢<br><br><br><br>
 
没有这样的要求, 不过你的函数好象没有那么多CALLBACK吧? 不要个个都取地址, <br>普通的参数只要定义的时候指定BYREF, 其实不用指定BYVAL即可, 就会自动传送参数地址,<br>你的程序没看过, 不知你的对不对,
 
谢谢你的指点,可不可以留下E—MAIL,我有一段程序请教你。
 
Declare Function StartUp Lib "Startup.dll" Alias "AddFontResourceA"(cLocalIp as string, iLocalPort as Long, deliver as &nbsp;Long, report as Long, bb as Long, cc as Long) as Long<br>private sub TDeliver(deliver as DeliverStr) '这个参数类型要自己定义<br>&nbsp; &nbsp; '这是回调函数<br>end sub<br><br>private sub TReport(Report as ReportStr) &nbsp; '这个参数类型要自己定义<br>&nbsp; &nbsp; '这是回调函数<br>end sub<br><br>现个函数参数调用时以&amp;TDeliver的方式使用<br>
 
谢谢各位大哥!<br>在调用到该DLL的另一个函数时还遇到这样一个问题““0x037d1bd9”指令引用“0x00000000”内存,该内存不能为“written””<br>程序如下:<br>Private Declare Function Submit Lib "SGIP.dll" (ByRef spnumber As String, ByRef chargenumber As String, ByVal user_count As Long, ByRef usernumber As String, ByRef corpid As String, ByRef service_type As String, fee_type As Byte, ByRef given_value As String, agent_flag As Byte, mo_fiag As Byte, priority As Byte, ByRef expire_time As String, ByRef schedule_time As String, report_flag As Byte, tp_pid As Byte, tp_udhi As Byte, message_coding As Byte, message_type As Byte, ByVal message_length As Long, ByRef message_content As String, ByRef reserve As String, ByRef sequencenumber1 As Long, ByRef sequencenumber2 As Long, ByRef sequencenumber3 As Long) As Long<br>Private Sub Command2_Click()<br>&nbsp; &nbsp;Dim x As Long<br>&nbsp; &nbsp;Dim sequencenumber1, sequencenumber2, sequencenumber3 As Long<br>&nbsp; &nbsp;Dim spnumber As String<br>&nbsp; &nbsp;Dim chargenuber As String<br>&nbsp; &nbsp;Dim uesernumber As String<br>&nbsp; &nbsp;Dim corid As String<br>&nbsp; &nbsp;Dim service_type As String<br>&nbsp; &nbsp;Dim fee_type As String<br>&nbsp; &nbsp;Dim fee_value As String<br>&nbsp; &nbsp;Dim given_value As String<br>&nbsp; &nbsp;Dim expire_time As String<br>&nbsp; &nbsp;Dim schedule_time As String<br>&nbsp; &nbsp;Dim message_content As String<br>&nbsp; &nbsp;Dim reserve As String<br>&nbsp; &nbsp;spnumber = "390000"<br>&nbsp; &nbsp;chargenuber = "000000000000000000000"<br>&nbsp; &nbsp;uesernumber = "13060698634"<br>&nbsp; &nbsp;corid = "390000"<br>&nbsp; &nbsp;service_type = ""<br>&nbsp; &nbsp;fee_type = "0"<br>&nbsp; &nbsp;fee_value = "0"<br>&nbsp; &nbsp;expire_time = ""<br>&nbsp; &nbsp;schedule_time = ""<br>&nbsp; &nbsp;message_content = "abc"<br>&nbsp; &nbsp;reserve = ""<br>&nbsp; &nbsp;<br>&nbsp; &nbsp;x = Submit(spnumber, chargenuber, 1, uesernumber, corid, "", "1", "0", "0", "0", "0", "", "", "0", "0", "0", "0", "0", 3, message_content, reserve, sequencenumber1, sequencenumber2, sequencenumber3)<br>End Sub<br><br>&nbsp;Submit函数是<br><br>Typedef &nbsp;unsigned char UINT_1;<br>Typedef &nbsp;unsigned short UINT_2;<br>Typedef &nbsp;unsigned int UINT_4;<br><br>int __stdcall Submit(char* spnumber,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* chargenumber, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int user_count,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* usernumber,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* corpid,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* service_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 fee_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* fee_value,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* given_value,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 agent_flag,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 mo_flag,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 priority,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* expire_time,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* schedule_time,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 report_flag,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 tp_pid,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 tp_udhi,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 message_coding,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_1 message_type,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_4 message_length,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* message_content,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char* reserve,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_4 *sequencenumber1,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; UINT_4 *sequencenumber2,<br>UINT_4 *sequencenumber3)<br>小弟急用,请指明错误,小弟不甚感激。<br><br>
 
太长了, 呵呵没空看仔细, 不过UINT_1, UINT_2,UINT_4可申明yl byte, short, long, 指针的请申明为Long,或 ByRef应该没问题
 
[?]为什么我还是触发不了回调函数。还有在函数中我把UINT_1结构的参数定义为byval xx as string时<br>在接收端接受到错误的数据?请帮忙!谢谢
 
后退
顶部