用C做的DLL中的函数,如何用Delphi调用表达! ( 积分: 100 )

  • 主题发起人 主题发起人 backup
  • 开始时间 开始时间
B

backup

Unregistered / Unconfirmed
GUEST, unregistred user!
如题:在C的头文件中是这样表达的<br>HANDLE (*MPUSBOpen)(DWORD instance, &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PCHAR pVID_PID, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PCHAR pEP, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwDir, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwReserved); &nbsp; &nbsp; &nbsp; &nbsp; // Input &amp;lt;Future Use&amp;gt;<br>DWORD (*MPUSBWrite)(HANDLE handle, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PVOID pData, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwLen, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PDWORD pLength, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Output<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwMilliseconds); &nbsp; &nbsp; // Input<br>如果换成用Delphi表达,该如何写呢?<br>我是这样写的,但是程序运行得不到正确结果:<br>type<br> &nbsp;DWORD = Longword;<br> &nbsp;PCHAR8 = &nbsp;array[0..MAXSIZE] of char;<br> &nbsp;PBYTE = array[0..MAXSIZE] of BYTE;<br> &nbsp;PDWORD = &nbsp;array[0..MAXSIZE] of DWORD;<br> &nbsp;PVOID = Pointer;<br> &nbsp;UINT = Cardinal;<br> &nbsp;THandle=HWND;<br><br>function _MPUSBOpen(instance:DWORD;pVID_PID:PCHAR8;pEP:PCHAR8;dwDir:DWORD;dwReserved:DWORD):THANDLE; stdcall;external 'mpusbapi.dll';<br>function _MPUSBWrite(handle:THANDLE;pData:PBYTE;dwLen:DWORD;var pLength:DWORD;dwMilliseconds:DWORD):DWORD; stdcall;external 'mpusbapi.dll';<br>
 
如题:在C的头文件中是这样表达的<br>HANDLE (*MPUSBOpen)(DWORD instance, &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PCHAR pVID_PID, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PCHAR pEP, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwDir, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwReserved); &nbsp; &nbsp; &nbsp; &nbsp; // Input &amp;lt;Future Use&amp;gt;<br>DWORD (*MPUSBWrite)(HANDLE handle, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PVOID pData, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwLen, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Input<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PDWORD pLength, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Output<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dwMilliseconds); &nbsp; &nbsp; // Input<br>如果换成用Delphi表达,该如何写呢?<br>我是这样写的,但是程序运行得不到正确结果:<br>type<br> &nbsp;DWORD = Longword;<br> &nbsp;PCHAR8 = &nbsp;array[0..MAXSIZE] of char;<br> &nbsp;PBYTE = array[0..MAXSIZE] of BYTE;<br> &nbsp;PDWORD = &nbsp;array[0..MAXSIZE] of DWORD;<br> &nbsp;PVOID = Pointer;<br> &nbsp;UINT = Cardinal;<br> &nbsp;THandle=HWND;<br><br>function _MPUSBOpen(instance:DWORD;pVID_PID:PCHAR8;pEP:PCHAR8;dwDir:DWORD;dwReserved:DWORD):THANDLE; stdcall;external 'mpusbapi.dll';<br>function _MPUSBWrite(handle:THANDLE;pData:PBYTE;dwLen:DWORD;var pLength:DWORD;dwMilliseconds:DWORD):DWORD; stdcall;external 'mpusbapi.dll';<br>
 
stdcall有问题,我没有看到C代码中有WINAPI或者__STDCALL之类的参数传递方式,你应该使用默认的C函数参数传递方式。
 
不光是调用问题, 他参数传递的完全是错的, 举个例子, c中要求的pVID_PID明显是个指针,参数长度只有4字节, 而他传递了MAX_SIZE字节的一个数组, 会成功才有鬼.<br>至少应该改成:<br>type<br> &nbsp;CHAR8 = &nbsp;array[0..MAXSIZE] of char;<br> &nbsp;PCHAR8 = ^CHAR8;<br> &nbsp;BYTES = array[0..MAXSIZE] of BYTE;<br> &nbsp;PBYTE = ^BYTES;<br> &nbsp;DWORDS = &nbsp;array[0..MAXSIZE] of DWORD;<br> &nbsp;PDWORD = ^DWORDS;<br><br>至于调用模式,应该是把stdcall改成cdel就可以了
 
后退
顶部