高手帮帮忙.Delphi调用VC--DLL问题 ( 积分: 200 )

  • 主题发起人 主题发起人 KingSoft
  • 开始时间 开始时间
K

KingSoft

Unregistered / Unconfirmed
GUEST, unregistred user!
高手帮帮忙<br>在VC里的一个DLL有这么个函数int&nbsp;hst_polling(long&nbsp;*recno,&nbsp;long&nbsp;ioboxno)<br>在Delphi里要如何声明调用这东东<br><br>我用了如下几种写法都是错误E文的..意思是&nbsp;参数类型错误<br>Function&nbsp;hst_polling(reco:PLongint;iobox:longint):integer;stdcall&nbsp;external&nbsp;'hostcm32.dll';<br><br>Function&nbsp;hst_polling(var&nbsp;reco:PLongint;iobox:longint):integer;stdcall&nbsp;external&nbsp;'hostcm32.dll';<br><br>Function&nbsp;hst_polling(var&nbsp;reco:Longint;iobox:longint):integer;stdcall&nbsp;external&nbsp;'hostcm32.dll';<br><br>在VB里调用声明如下:<br>Public&nbsp;Declare&nbsp;Function&nbsp;hst_polling&nbsp;Lib&nbsp;&quot;hostcm32.dll&quot;&nbsp;(recno&nbsp;As&nbsp;Long,&nbsp;ByVal&nbsp;ioboxno&nbsp;As&nbsp;Long)&nbsp;As&nbsp;Intege<br><br>使用时直接&nbsp;hst_polling(1,1)&nbsp;就OK了,,可在D里就是怎么都搞不来..高手们帮帮忙吧
 
补充一下&nbsp;Hst_polling&nbsp;函数<br>Polling hst_polling<br>&nbsp;Function:<br> Polling&nbsp;is&nbsp;done&nbsp;and&nbsp;establish&nbsp;the&nbsp;data&nbsp;linking&nbsp;for&nbsp;connectd&nbsp;DT700/750.<br> In&nbsp;this&nbsp;case&nbsp;the&nbsp;territory&nbsp;for&nbsp;the&nbsp;communication&nbsp;management&nbsp;information&nbsp;stored&nbsp;table&nbsp;is&nbsp;ensured.&nbsp;Call&nbsp;hst_getcinffirst,&nbsp;hst_getcinffirst&nbsp;to&nbsp;acquire&nbsp;the&nbsp;content&nbsp;of&nbsp;this&nbsp;cable.<br>&nbsp;Form:<br>int&nbsp;hst_polling(long&nbsp;*recno,&nbsp;long&nbsp;ioboxno)<br>&nbsp;Parameter:<br>recno Start&nbsp;record&nbsp;number&nbsp;for&nbsp;ID&nbsp;checking&nbsp;[Input]<br> End&nbsp;record&nbsp;number&nbsp;for&nbsp;ID&nbsp;checking[Output]<br> 1~128<br>ioboxno Connection&nbsp;I/O&nbsp;box&nbsp;number<br>&nbsp;Return&nbsp;value:<br>0~ Normal&nbsp;End.&nbsp;Return&nbsp;value&nbsp;is&nbsp;the&nbsp;number&nbsp;of&nbsp;HTs&nbsp;which&nbsp;the&nbsp;response&nbsp;return.<br>-1 Abnormal&nbsp;End.&nbsp;<br>-11 Interrupt.&nbsp;Interrupt&nbsp;key①&nbsp;is&nbsp;pressed&nbsp;and&nbsp;the&nbsp;management&nbsp;is&nbsp;interrupted.<br>-12 Interrupt.&nbsp;Interrupt&nbsp;key②&nbsp;is&nbsp;pressed&nbsp;and&nbsp;the&nbsp;management&nbsp;is&nbsp;interrupted.<br>-15 Error.&nbsp;Parameter&nbsp;is&nbsp;not&nbsp;correct.
 
Function&nbsp;hst_polling(var&nbsp;reco:Longint;iobox:longint):integer;stdcall&nbsp;external&nbsp;'hostcm32.dll';<br><br>调用<br>var<br>&nbsp;&nbsp;reco:&nbsp;Longint;<br><br>reco&nbsp;:=&nbsp;1;<br>hst_polling(reco,&nbsp;1);
 
Function&nbsp;hst_polling(var&nbsp;reco:integer;iobox:integer):integer;stdcall&nbsp;external&nbsp;'hostcm32.dll';
 
查一下hst_polling函数的调用方式,&nbsp;应使用stdcall,&nbsp;VC写DLL的人一般只管自己调用成功,&nbsp;不管D或VB是否能否,&nbsp;这种错误常见<br><br>VC中函数定义应该为:<br>__declspec(dllexport)&nbsp;int&nbsp;FAR&nbsp;PASCAL&nbsp;hst_polling(......);<br>注意是用:FAR&nbsp;PASCAL,&nbsp;而非用:&nbsp;__cdecl<br><br>VB能用有两种可能,&nbsp;如果VC中DLL中调用方式正确是用FAR&nbsp;PASCAL,&nbsp;则只是D的问题<br>但是正在这种可能,&nbsp;因为这个函数的两个参数都是LONG,&nbsp;实际调用参数顺序可能反了,&nbsp;<br>可在VB中调用未必一定结果就对<br><br>function&nbsp;hst_polling&nbsp;(var&nbsp;recno&nbsp;:&nbsp;LongInt,&nbsp;&nbsp;ioboxno&nbsp;:&nbsp;LongInt)&nbsp;:&nbsp;Integer&nbsp;cdecl&nbsp;&nbsp;{$IFDEF&nbsp;WIN32}&nbsp;stdcall&nbsp;{$ENDIF};<br><br>D声明中可将stdcall&nbsp;改为cdecl&nbsp;试试
 
to&nbsp;htw:谢谢htw的分析...您提供的这种方法我也有试过的..提示同样的错误!<br>高手们..快来帮帮忙吧
 
to&nbsp;&nbsp;tseug,asksomeone&nbsp;这两种方法..我都也有试用..也是提试&nbsp;反回值-15&nbsp;大意是参数错误吧
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=691213
 
to&nbsp;tseug&nbsp;按那里的方法..提示同样的错误.........
 
顺便再问个问题.如下C的结构我在D里.的写法是不是正确的<br>&nbsp;Form:<br>int&nbsp;hst_getcinffirst(CINFTBL&nbsp;*cinftbl)<br>&nbsp;Parameter:<br>typedef&nbsp;struct&nbsp;CINFTBL&nbsp;{ Data&nbsp;acquirement&nbsp;territory&nbsp;for&nbsp;the&nbsp;stored&nbsp;table&nbsp;of&nbsp;the<br>&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;communication&nbsp;management&nbsp;information.<br> UCHAR&nbsp;htid[6] ID&nbsp;letter&nbsp;line<br> Set&nbsp;ID&nbsp;letter&nbsp;line&nbsp;of&nbsp;dt700/750&nbsp;in&nbsp;sending&nbsp;management.<br> UCHAR&nbsp;htdmy[2] Dummy<br> This&nbsp;command&nbsp;is&nbsp;no&nbsp;meaning.<br> long&nbsp;adv Priority&nbsp;Order<br> Priority&nbsp;order&nbsp;is&nbsp;set.<br> long&nbsp;fileno File&nbsp;number<br> Set&nbsp;the&nbsp;sending&nbsp;file&nbsp;number&nbsp;in&nbsp;requesting&nbsp;the&nbsp;sending&nbsp;file&nbsp;from&nbsp;dt700/750.<br> long&nbsp;filesize Total&nbsp;of&nbsp;file&nbsp;size<br> Set&nbsp;the&nbsp;total&nbsp;sending&nbsp;file&nbsp;in&nbsp;requesting&nbsp;the&nbsp;sending&nbsp;file&nbsp;from&nbsp;dt700/750.<br> long&nbsp;jobcmd Management&nbsp;request&nbsp;command<br> Set&nbsp;the&nbsp;management&nbsp;command&nbsp;requested&nbsp;from&nbsp;dt700/750&nbsp;in&nbsp;&nbsp;establishing&nbsp;the<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data&nbsp;linking.<br> 0:file&nbsp;receiving(PC←HT)、1:file&nbsp;sending(PC→HT)、<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;255:cutting&nbsp;request<br> long&nbsp;datatype Kind&nbsp;of&nbsp;data<br> Set&nbsp;the&nbsp;kind&nbsp;of&nbsp;the&nbsp;objected&nbsp;data&nbsp;requested&nbsp;the&nbsp;management&nbsp;fromdt700/750.<br>}&nbsp;cinftbl<br><br>下面是我在D里的写法<br>Type<br>&nbsp;&nbsp;CINFTBL&nbsp;=&nbsp;record<br>&nbsp;&nbsp;&nbsp;&nbsp;htid&nbsp;:String[6];<br>&nbsp;&nbsp;&nbsp;&nbsp;htdmy:String[2];<br>&nbsp;&nbsp;&nbsp;&nbsp;dav&nbsp;&nbsp;&nbsp;:LongInt;<br>&nbsp;&nbsp;&nbsp;&nbsp;fileno&nbsp;:&nbsp;LongInt;<br>&nbsp;&nbsp;&nbsp;&nbsp;filesize&nbsp;:LongInt;<br>&nbsp;&nbsp;&nbsp;&nbsp;jobcmd&nbsp;:LongInt;<br>&nbsp;&nbsp;&nbsp;&nbsp;datatype&nbsp;:LongInt;<br>End;
 
多人接受答案了。
 
后退
顶部