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. Also add CharSet = CharSet.Auto.
[DllImport ("Dogskin.dll", EntryPoint = "Encode", CharSet = CharSet.Auto, callingconvention = CALLINGCONVENTION.CDECL)]
public static extern StringBuilder Encode (string passWord);
Be aware of the corresponding data types in C + + and 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.int32
Reproduced 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//c++ a character in one byte, and a 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//c# before calling to define int variable name = 0;
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//c# before calling to define the byte variable name = new byte ();
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); Corresponds to C #:p ublic delegate Double fun_type1 (double);
char* Operation C + +: char*; Correspondence 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);
*
*
*/
Dogskin.dll method Encode (char* str) is called in C #