VB的DLL调用怎么“DLL调用约定错误”

baiyongming 2008-10-06 02:43:44
"PrinterUsb.dll"里的数据类型及函数如下:
const int DEVNUM = 10;
const int PATHLEN = 200;

typedef struct
{
char strDevPath[PATHLEN];
}DEVPATH;

typedef struct
{
DEVPATH DevPath[DEVNUM];
int DevNum;
}DEVINFO;

int GetDevicePath(DEVINFO&);
bool Open(int PortNum);
bool Write(char *pBuf,DWORD nNumberOfBytesToWrite,DWORD &NumberOfBytesWritten);
void Close();


我在USB里调用DLL,作如下声明:


Public Const DevNum = 10
Public Const PATHLEN = 200
Public Type DEVPATH
strDevPath(0 To PATHLEN) As String
End Type

Public Type DEVINFO
iDevPath(0 To DevNum) As DEVPATH
DevNum As Integer
End Type

Public Declare Function GetDevicePath _
Lib "PrinterUsb.dll" _
(ByRef sDevInfo As DEVINFO) _
As Long

Public Declare Function OpenUSB _
Lib "PrinterUsb.dll" Alias "Open" _
(ByVal PortNum As Integer) _
As Boolean

Public Declare Function WriteUSB _
Lib "PrinterUsb.dll" Alias "Write" _
(ByVal pBuf As String, _
ByVal nNumberOfBytesToWrite As Long, _
ByVal nNumberOfBytesWritten As Long) _
As Boolean

Public Declare Sub CloseUSB _
Lib "PrinterUsb.dll" Alias "Close" ()


程序如下:
Private Sub cmdUSBTest_Click()
Dim MyDevInfo As DEVINFO
Dim ESC As String: ESC = Chr(27)
Dim strCmd As String
Dim nNumberOfBytesToWrite As Long: nNumberOfBytesToWrite = 0
Dim nNumberOfBytesWritten As Long: nNumberOfBytesWritten = 10

strCmd = "hello"


GetDevicePath MyDevInfo
If MyDevInfo.DevNum = 0 Then
MsgBox "未检测到USB设备!"
End
End If

If OpenUSB(0) = False Then
MsgBox "打开USB设备失败!"
End
End If

WriteUSB strCmd, nNumberOfBytesToWrite, nNumberOfBytesWritten

CloseUSB


End Sub



执行GetDevicePath MyDevInfo时就出现“实时错误49,DLL调用约定错误”
我把
Public Declare Function GetDevicePath _
Lib "PrinterUsb.dll" _
(ByRef sDevInfo As DEVINFO) _
As Long
改成
Public Declare Function GetDevicePath _
Lib "PrinterUsb.dll" _
(ByVal sDevInfo As DEVINFO) _
As Long
就出现“编译错误:用户类型不能用”。

现在怎么办,哪儿错了,要怎么改,原因是什么呢,谢谢!
...全文
410 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenhui530 2008-10-07
  • 打赏
  • 举报
回复
int WINAPI GetDevicePath(DEVINFO&);
bool WINAPI Open(int PortNum);
bool WINAPI Write(char *pBuf,DWORD nNumberOfBytesToWrite,DWORD &NumberOfBytesWritten);
void WINAPI Close();
bob008 2008-10-07
  • 打赏
  • 举报
回复
另外个帖子里。。。。 AS DEVPATH这里估计是定长

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧