C++原型
BOOL __stdcall Open (HANDLE *handle,DWORD CardId);
C#对应类型
[DllImport("USB.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern bool Open(ref IntPtr intptr, Byte CardId);
函数正常运行,但是问题出现了。这里的 ref IntPtr intptr 每次打开后,intptr 这个值 一直在改变。
C++中 handle 的值是固定不变的。
[return : MarshalAs( UnmanagedType.Bool)]//4 字节布尔值(true != 0、false = 0)。这是 Win32 BOOL 类型。
public static extern bool Open(IntPtr intptr, uint CardId);