"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
就出现“编译错误:用户类型不能用”。 现在怎么办,哪儿错了,要怎么改,原因是什么呢,谢谢!
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
就出现“编译错误:用户类型不能用”。 现在怎么办,哪儿错了,要怎么改,原因是什么呢,谢谢!
char strDevPath[PATHLEN];
他俩不一样
strDevPath(0 To PATHLEN-1) As byte