c# c++数据类型对照

来源:互联网 发布:淘宝佣金骗术 编辑:程序博客网 时间:2024/06/06 02:12

最近再做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