最近再做c#調用c++編寫的dll。在網上查了查兩者的數據對照,自己再重新總結一遍,可能會有重複或者多種方案。如果有錯誤希望大家給提出,反正我也不改!
c++ c#
HANDLE(void *) ----------------------------------------System.IntPtr
Byte(unsigned char) ----------------------------------System.Byte
SHORT(short) ------------------------------------------System.Int16
WORD(unsigned short) -----------------------------System.UInt16
INT(int) ---------------------------------------------------System.Int16
INT(int) ---------------------------------------------------System.Int32
UINT(unsigned int) -----------------------------------System.UInt16
UINT(unsigned int) -----------------------------------System.UInt32
LONG(long) -------------------------------------------- System.Int32
ULONG(unsigned long) ---------------------------- System.UInt32
DWORD(unsigned long) ----------------------------System.UInt32
DECIMAL ------------------------------------------------ System.Decimal
BOOL(long) ---------------------------------------------System.Boolean
CHAR(char) ---------------------------------------------System.Char
LPSTR(char *) ------------------------------------------System.String
LPWSTR(wchar_t *) -----------------------------------System.String
LPCSTR(const char *) --------------------------------System.String
LPCWSTR(const wchar_t *) -------------------------System.String
PCAHR(char *) -------------------------------------------System.String
BSTR --------------------------------------------------------System.String
FLOAT(float) -----------------------------------------------System.Single
DOUBLE(double) -----------------------------------------System.Double
VARIANT -----------------------------------------------------System.Object
PBYTE(byte *) -----------------------------------------------System.Byte[]
BSTR ----------------------------------------------------------StringBuilder
LPCTSTR ---------------------------------------------------- StringBuilder
LPCTSTR ---------------------------------------------------- string
LPTSTR -------------------------------------------------------[MarshalAs(UnmanagedType.LPTStr)] string
LPTSTR 輸出變量名 --------------------------------------StringBuilder 輸出變量名
LPCWSTR --------------------------------------------------- IntPtr
BOOL ----------------------------------------------------------bool
HMODULE ---------------------------------------------------IntPtr
HINSTANCE -------------------------------------------------IntPtr
結構體 --------------------------------------------------------public struct 結構體{};
結構體 **變量名 -------------------------------------------out 變量名 //C#中提前申明一個結構體實例化後的變量名
結構體 &變量名 ------------------------------------------- ref 結構體 變量名
WORD --------------------------------------------------------ushort
DWORD ------------------------------------------------------uint
DWORD ------------------------------------------------------int
UCHAR -------------------------------------------------------int
UCHAR -------------------------------------------------------byte
UCHAR* -----------------------------------------------------string
UCHAR* -----------------------------------------------------IntPtr
GUID ----------------------------------------------------------Guid
Handle --------------------------------------------------------IntPtr
HWND --------------------------------------------------------IntPtr
DWORD ------------------------------------------------------int
COLORREF -------------------------------------------------uint
unsigned char ----------------------------------------------byte
unsigned char * --------------------------------------------ref byte
unsigned char * --------------------------------------------[MarshalAs(UnmanagedType.LPArray)] byte[]
unsigned char * --------------------------------------------[MarshalAs(UnmanagedType.LPArray)] Intptr
unsigned char & --------------------------------------------ref byte
unsigned char ----------------------------------------------byte
unsigned short --------- -----------------------------------ushort
unsigned int --------------------------------------------------uint
unsigned long -----------------------------------------------ulong