C#调用C++DLL出现的错误
C++的.h声明
__declspec(dllimport)
FT_HANDLE WINAPI FT_W32_CreateFile(
LPCSTR lpszName,
DWORD dwAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreate,
DWORD dwAttrsAndFlags,
HANDLE hTemplate
);
___________________________________________
C#
using FT_HANDLE=System.IntPtr;
using LPVOID = System.IntPtr;
using LPCSTR=System.String;
using FT_STATUS = System.Int64;
using DWORD = System.UInt64;
using HANDLE = System.IntPtr;
using BOOL=System.Boolean ;
___________________________________________________________________
[DllImport( "FTD2XX.Dll ")]
public static extern FT_HANDLE FT_W32_CreateFile(LPCSTR lpszName, DWORD dwAccess, DWORD dwShareMode, out
_SECURITY_ATTRIBUTES
lpSecurityAttributes, DWORD dwCreate, DWORD
dwAttrsAndFlags, HANDLE hTemplate);
public struct _SECURITY_ATTRIBUTES
{
public DWORD nLength;
public LPVOID lpSecurityDescriptor;
public BOOL bInheritHandle;
} ;
public static void SendPackage(string str)
{
FT_STATUS ftStatus;
FT_HANDLE ftHandle;
string buf= "usb ";
_SECURITY_ATTRIBUTES tmp;
//ftStatus = FT_ListDevices(0, Buf, FT_LIST_BY_INDEX | FT_OPEN_BY_SERIAL_NUMBER);
ftHandle = FT_W32_CreateFile(buf, (ulong)0x80000000L | 0x40000000L, 0, out tmp, (ulong)3, (ulong)
0x00000080 | 0x40000000 | 1, (IntPtr)0);
}
提示出错:
对 PInvoke 函数“ProtocolX!ProtocolX.ProtocolUsb2_0_1::FT_W32_CreateFile”的调用导致堆栈不对称。原因可能是托管的
PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
请高手帮助
------解决方案--------------------帮顶
------解决方案--------