动态库对象创建失败,不可以调用动态库函数,该如何解决
动态库对象创建失败,不可以调用动态库函数
VB调用方法
Dim bSectNum(16) As Byte
bSectNum(0) = &H6
bSectNum(1) = &H7
bSectNum(2) = &H8
bSectNum(3) = &H9
bSectNum(4) = &HA
bSectNum(5) = &HB
bSectNum(6) = &HFF
bSectNum(7) = &HFF
bSectNum(8) = &HFF
bSectNum(9) = &HC
bSectNum(10) = &HD
hwnd, GB_GB, True, bSectNum(), 0)
函数VB原型 Public Declare Function CreateObject Lib "Reader.dll" (ByVal hwnd As Long, ByVal Lang As CHINESETYPE, ByVal Alignment As Long, ByRef SectorNum() As Byte, ByVal MyAddress As Long) As Boolean
函数C#原型[DllImport(readerproc, SetLastError=true), SuppressUnmanagedCodeSecurity]
public static extern bool CreateObject(IntPtr hwnd, CHINESETYPE Lang , bool Alignment , byte [] SectorNum, long MyAddress);
用VB调用之后返回值为false,用C#调用函数返回True。不知道问题在哪?请协助
------解决方案--------------------
除了 bool 的长度,VB 数组是 SAFEARRAY,C 数组是 Byte* 指针,不匹配。
VB调用方法
Dim bSectNum(16) As Byte
bSectNum(0) = &H6
bSectNum(1) = &H7
bSectNum(2) = &H8
bSectNum(3) = &H9
bSectNum(4) = &HA
bSectNum(5) = &HB
bSectNum(6) = &HFF
bSectNum(7) = &HFF
bSectNum(8) = &HFF
bSectNum(9) = &HC
bSectNum(10) = &HD
hwnd, GB_GB, True, bSectNum(), 0)
函数VB原型 Public Declare Function CreateObject Lib "Reader.dll" (ByVal hwnd As Long, ByVal Lang As CHINESETYPE, ByVal Alignment As Long, ByRef SectorNum() As Byte, ByVal MyAddress As Long) As Boolean
函数C#原型[DllImport(readerproc, SetLastError=true), SuppressUnmanagedCodeSecurity]
public static extern bool CreateObject(IntPtr hwnd, CHINESETYPE Lang , bool Alignment , byte [] SectorNum, long MyAddress);
用VB调用之后返回值为false,用C#调用函数返回True。不知道问题在哪?请协助
------解决方案--------------------
除了 bool 的长度,VB 数组是 SAFEARRAY,C 数组是 Byte* 指针,不匹配。
- VB code
Public Declare Function CreateObject Lib "Reader.dll" _ (ByVal hwnd As Long, _ ByVal Lang As CHINESETYPE, _ ByVal Alignment As Long, _ ByRef SectorNum As Byte, _ ByVal MyAddress As Long) As Long Dim bSectNum(16) As Byte Dim lRet As Long lRet = CreaeObject(hwnd, Lang, Alignment, bSectNum(0), MyAddress) If lRet = 0 Then Exit Sub