A function call causes a stack asymmetry. The reason may be that the managed PInvoke signature does not match the unmanaged target signature. Add the CallingConvention parameter to the DllImport, [DllImport (Pcap_dll, CharSet= CharSet.Auto, CallingConvention =callingconvention.cdecl)] Be aware that C++corresponds to the data type in net://C++:char *----c#:string//Incoming Parameters//C++:char *----C#:stringbuilder//Outgoing Parameters//C++:char * Variable name----C#:REF string variable name//C++:char * Input variable name----c#:string input variable name//C++:char * Output variable name----C#:[marshalas (UNMANAGEDTYPE.LPSTR)] StringBuilder output variable name//C++:short (short)----c#:system.int16//C++:long (LONG)----C#:system.int32Reproduced Collection://C # calls C + + DLLs to compile all the data type conversions, there may be duplicate or multiple scenarios, self-test//c++:handle (void *)----c#:system.intptr//c++:byte (unsigned char)----c#:system.byte//C++:short (short)----c#:system.int16//C++:word (unsigned short)----c#:system.uint16//C++:int (INT)----c#:system.int16//C++:int (INT)----C#:system.int32//c++:uint (unsigned int)----C#:system.uint16//c++:uint (unsigned int)----C#:system.uint32//C++:long (LONG)----C#:system.int32//C++:ulong (unsigned long)----C#:system.uint32//C + +:D Word (unsigned long)----C#:system.uint32//C + +:D ecimal----C#:system.decimal//C++:bool (long)----C#:system.boolean//C++:char (CHAR)----C#:system.char//c++:lpstr (char *)----c#:system.string//c++:lpwstr (wchar_t *)----c#:system.string//c++:lpcstr (const char *)----c#:system.string//c++:lpcwstr (const wchar_t *)----c#:system.string//C + +:P Cahr (char *)----c#:system.string//c++:bstr----c#:system.string//c++:float (FLOAT)----C#:system.single//C + +:D ouble (DOUBLE)----c#:system.double//c++:variant----C#:system.object//C + +:P byte (byte *)----c#:system.byte[]//c++:bstr----C#:stringbuilder//c++:lpctstr----C#:stringbuilder//c++:lpctstr----c#:string//c++:lptstr----C#:[marshalas (UNMANAGEDTYPE.LPTSTR)] string//C++:LPTSTR Output Variable name----c#:stringbuilder Output variable name//c++:lpcwstr----C#:intptr//c++:bool----C#:bool//c++:hmodule----C#:intptr//c++:hinstance----C#:intptr//C + +: struct----C #:p ublic struct struct {}; //C + +: struct * * variable name----c#:out variable name//C # Advance declaration of a struct-instantiated variable name//C + +: struct & variable name----c#:ref struct variable name//C++:word----C#:ushort//C + +:D Word----c#:uint//C + +:D Word----c#:int//C++:uchar----C#:int//C++:uchar----C#:byte//c++:uchar*----c#:string//c++:uchar*----C#:intptr//c++:guid----C#:guid//c++:handle----C#:intptr//c++:hwnd----C#:intptr//C + +:D Word----c#:int//c++:colorref----C#:uint//c++:unsigned char----c#:byte//c++:unsigned char *----C#:REF byte//c++:unsigned char *----c#:[marshalas (UnmanagedType.LPArray)] byte[]//c++:unsigned char *----c#:[marshalas (UnmanagedType.LPArray)] Intptr//c++:unsigned char &----c#:ref byte//c++:unsigned char variable name----c#:byte variable name//c++:unsigned Short variable name----c#:ushort variable name//c++:unsigned int variable name----c#:uint variable name//c++:unsigned Long variable name----c#:ulong variable name//C++:char variable name----c#:byte variable name//one character in C + + is represented by one byte, and one character in C # is represented by two bytes//C++:char array name [array size]----C#:marshalas (unmanagedtype.byvaltstr, SizeConst = array size)] public string array name; UShort//C++:char *----c#:string//Incoming Parameters//C++:char *----C#:stringbuilder//Outgoing Parameters//C++:char * Variable name----C#:REF string variable name//C++:char * Input variable name----c#:string input variable name//C++:char * Output variable name----C#:[marshalas (UNMANAGEDTYPE.LPSTR)] StringBuilder output variable name//C++:char * *----c#:string//C++:char * * Variable name----C#:REF string variable name//c++:const char *----c#:string//c++:char[]----c#:string//c++:char variable name [array size]----C#:[marshalas (unmanagedtype.byvaltstr,sizeconst= array size)] public string variable name; //c++:struct struct Name * variable name----c#:ref struct name variable name//C + +: Delegate variable name----C #: Delegate variable name//c++:int----C#:int//c++:int----C#:ref int//c++:int &----C#:ref int//c++:int *----C#:REF int//you need to define the INT variable name = 0 before calling in C #; //C + +:* int----C#:intptr//c++:int32 piptr *----c#:int32[]//c++:float piptr *----c#:float[]//C + +:d ouble** array name----C#:REF Double array name//C + +:d ouble*[] Array name----C#:REF Double array name//c++:long----C#:int//c++:ulong----C#:int//c++:uint8 *----c#:ref byte//you need to define a byte variable name = new byte () before calling in C #; //c++:handle----C#:intptr//c++:hwnd----C#:intptr//c++:void *----c#:intptr//c++:void * User_obj_param----c#:intptr User_obj_param//C++:void * Object name----C #:([MarshalAs (unmanagedtype.asany)]object object name//C++:char, INT8, SBYTE, char----c#:system.sbyte//c++:short, Short int, INT16, short----c#:system.int16//C++:int, long, long int, INT32, LONG32, BOOL, int----C#:system.int32//C++:__int64, INT64, longlong----C#:system.int64//c++:unsigned Char, UINT8, UCHAR, BYTE----c#:system.byte//c++:unsigned Short, UINT16, USHORT, WORD, ATOM, WCHAR, __wchar_t----c#:system.uint16//c++:unsigned, unsigned int, UINT32, ULONG32, DWORD32, ULONG, DWORD, UINT----C#:system.uint32//c++:unsigned __int64, UINT64, Dwordlong, ulonglong----C#:system.uint64//c++:float, float----c#:system.single//C + +:d ouble, long double, double----c#:system.double//Win32 Types----CLR Type//structs need to redefine a struct in C #//the callback callback function needs to be encapsulated in a delegate, delegate static extern int Funcallback (string str); //unsigned char** ppimage replaced with IntPtr ppimage//int& nwidth replaced with ref int nwidth//int*, Int&, then all can be ref int corresponding//double needle Finger type parameter, can be used ref INTPTR//The function pointer uses C + +: TypeDef double (*FUN_TYPE1) (double), corresponding C #:p ublic delegate Double fun_type1 (double); //char* Operation C + +: char*; corresponding c#:stringbuilder; //use pointers in C #: Add unsafe where you need to use pointers//unsigned char corresponds to public byte /** typedef void (*CALLBACKFUN1W) (wchar_t*, void* parg); * typedef void (*CALLBACKFUN1A) (char*, void* parg); * BOOL Bioprint_sensor_api dllFun1 (CALLBACKFUN1 pCallbackFun1, void* parg); * Call mode is * [Unmanagedfunctionpointer (CALLINGCONVENTION.CDECL)] * public delegate void CallbackFunc1 ([MarshalAs ( UNMANAGEDTYPE.LPWSTR)] StringBuilder strName, IntPtr parg); * * */
C # calls C + + DLLs (type control)