http://www.it165.net/pro/html/201207/3221.html
//
C++中的DLL函数原型為
002.
//extern "C" __declspec(dllexport) bool 方法名一(const char* 变量名1, unsigned char* 变量名2)
003.
//extern "C" __declspec(dllexport) bool 方法名二(const unsigned char* 变量名1, char* 变量名2)
004.
005.
//C#调用C++的DLL搜集整理的所有数据类型转换方式,可能会有重復或者多种方案,自己多测试
006.
//c++:HANDLE(void *) ---- c#:System.IntPtr
007.
//c++:Byte(unsigned char) ---- c#:System.Byte
008.
//c++:SHORT(short) ---- c#:System.Int16
009.
//c++:WORD(unsigned short) ---- c#:System.UInt16
010.
//c++:INT(int) ---- c#:System.Int16
011.
//c++:INT(int) ---- c#:System.Int32
012.
//c++:UINT(unsigned int) ---- c#:System.UInt16
013.
//c++:UINT(unsigned int) ---- c#:System.UInt32
014.
//c++:LONG(long) ---- c#:System.Int32
015.
//c++:ULONG(unsigned long) ---- c#:System.UInt32
016.
//c++:DWORD(unsigned long) ---- c#:System.UInt32
017.
//c++:DECIMAL ---- c#:System.Decimal
018.
//c++:BOOL(long) ---- c#:System.Boolean
019.
//c++:CHAR(char) ---- c#:System.Char
020.
//c++:LPSTR(char *) ---- c#:System.String
021.
//c++:LPWSTR(wchar_t *) ---- c#:System.String
022.
//c++:LPCSTR(const char *) ---- c#:System.String
023.
//c++:LPCWSTR(const wchar_t *) ---- c#:System.String
024.
//c++:PCAHR(char *) ---- c#:System.String
025.
//c++:BSTR ---- c#:System.String
026.
//c++:FLOAT(float) ---- c#:System.Single
027.
//c++:DOUBLE(double) ---- c#:System.Double
028.
//c++:VARIANT ---- c#:System.Object
029.
//c++:PBYTE(byte *) ---- c#:System.Byte[]
030.
031.
//c++:BSTR ---- c#:StringBuilder
032.
//c++:LPCTSTR ---- c#:StringBuilder
033.
//c++:LPCTSTR ---- c#:string
034.
//c++:LPTSTR ---- c#:[MarshalAs(UnmanagedType.LPTStr)] string
035.
//c++:LPTSTR 输出变量名 ---- c#:StringBuilder 输出变量名
036.
//c++:LPCWSTR ---- c#:IntPtr
037.
//c++:BOOL ---- c#:bool
038.
//c++:HMODULE ---- c#:IntPtr
039.
//c++:HINSTANCE ---- c#:IntPtr
040.
//c++:结构体 ---- c#:public struct 结构体{};
041.
//c++:结构体 **变量名 ---- c#:out 变量名 //C#中提前申明一个结构体实例化后的变量名
042.
//c++:结构体 &变量名 ---- c#:ref 结构体 变量名
043.
//c++:WORD ---- c#:ushort
044.
//c++:DWORD ---- c#:uint
045.
//c++:DWORD ---- c#:int
046.
047.
//c++:UCHAR ---- c#:int
048.
//c++:UCHAR ---- c#:byte
049.
//c++:UCHAR* ---- c#:string
050.
//c++:UCHAR* ---- c#:IntPtr
051.
052.
//c++:GUID ---- c#:Guid
053.
//c++:Handle ---- c#:IntPtr
054.
//c++:HWND ---- c#:IntPtr
055.
//c++:DWORD ---- c#:int
056.
//c++:COLORREF ---- c#:uint
057.
058.
//c++:unsigned char ---- c#:byte
059.
//c++:unsigned char * ---- c#:ref byte
060.
//c++:unsigned char * ---- c#:[MarshalAs(UnmanagedType.LPArray)] byte[]
061.
//c++:unsigned char * ---- c#:[MarshalAs(UnmanagedType.LPArray)] Intptr
062.
063.
//c++:unsigned char & ---- c#:ref byte
064.
//c++:unsigned char 变量名 ---- c#:byte 变量名
065.
//c++:unsigned short 变量名 ---- c#:ushort 变量名
066.
//c++:unsigned int 变量名 ---- c#:uint 变量名
067.
//c++:unsigned long 变量名 ---- c#:ulong 变量名
068.
069.
//c++:char 变量名 ---- c#:byte 变量名 //C++中一个字符用一个字节表示,C#中一个字符用两个字节表示
070.
//c++:char 数组名[数组大小] ---- c#:MarshalAs(UnmanagedType.ByValTStr, SizeConst = 数组大小)] public string 数组名; ushort
071.
072.
//c++:char * ---- c#:string //传入参数
073.
//c++:char * ---- c#:StringBuilder//传出参数
074.
//c++:char *变量名 ---- c#:ref string 变量名
075.
//c++:char *输入变量名 ---- c#:string 输入变量名
076.
//c++:char *输出变量名 ---- c#:[MarshalAs(UnmanagedType.LPStr)] StringBuilder 输出变量名
077.
078.
//c++:char ** ---- c#:string
079.
//c++:char **变量名 ---- c#:ref string 变量名
080.
//c++:const char * ---- c#:string
081.
//c++:char[] ---- c#:string
082.
//c++:char 变量名[数组大小] ---- c#:[MarshalAs(UnmanagedType.ByValTStr,SizeConst=数组大小)] public string 变量名;
083.
084.
//c++:struct 结构体名 *变量名 ---- c#:ref 结构体名 变量名
085.
//c++:委托 变量名 ---- c#:委托 变量名
086.
087.
//c++:int ---- c#:int
088.
//c++:int ---- c#:ref int
089.
//c++:int & ---- c#:ref int
090.
//c++:int * ---- c#:ref int //C#中调用前需定义int 变量名 = 0;
091.
www.it165.net"DISPLAY: none"
>
092.
//c++:*int ---- c#:IntPtr
093.
//c++:int32 PIPTR * ---- c#:int32[]
094.
//c++:float PIPTR * ---- c#:float[]
095.
096.
097.
//c++:double** 数组名 ---- c#:ref double 数组名
098.
//c++:double*[] 数组名 ---- c#:ref double 数组名
099.
//c++:long ---- c#:int
100.
//c++:ulong ---- c#:int
101.
102.
//c++:UINT8 * ---- c#:ref byte //C#中调用前需定义byte 变量名 = new byte();
103.
104.
105.
//c++:handle ---- c#:IntPtr
106.
//c++:hwnd ---- c#:IntPtr
107.
108.
109.
//c++:void * ---- c#:IntPtr
110.
//c++:void * user_obj_param ---- c#:IntPtr user_obj_param
111.
//c++:void * 对象名称 ---- c#:([MarshalAs(UnmanagedType.AsAny)]Object 对象名称
112.
113.
114.
115.
//c++:char, INT8, SBYTE, CHAR ---- c#:System.SByte
116.
//c++:short, short int, INT16, SHORT ---- c#:System.Int16
117.
//c++:int, long, long int, INT32, LONG32, BOOL , INT ---- c#:System.Int32
118.
//c++:__int64, INT64, LONGLONG ---- c#:System.Int64
119.
//c++:unsigned char, UINT8, UCHAR , BYTE ---- c#:System.Byte
120.
//c++:unsigned short, UINT16, USHORT, WORD, ATOM, WCHAR , __wchar_t ---- c#:System.UInt16
121.
//c++:unsigned, unsigned int, UINT32, ULONG32, DWORD32, ULONG, DWORD, UINT ---- c#:System.UInt32
122.
//c++:unsigned __int64, UINT64, DWORDLONG, ULONGLONG ---- c#:System.UInt64
123.
//c++:float, FLOAT ---- c#:System.Single
124.
//c++:double, long double, DOUBLE ---- c#:System.Double
125.
126.
//Win32 Types ---- CLR Type
127.
//Struct需要在C#里重新定义一个Struct
128.
//CallBack回调函数需要封装在一个委托里,delegate static extern int FunCallBack(string str);
129.
130.
//unsigned char** ppImage替换成IntPtr ppImage
131.
//int& nWidth替换成ref int nWidth
132.
//int*, int&, 则都可用 ref int 对应
133.
//双针指类型参数,可以用 ref IntPtr
134.
//函数指针使用c++: typedef double (*fun_type1)(double); 对应 c#:public delegate double fun_type1(double);
135.
//char* 的操作c++: char*; 对应 c#:StringBuilder;
136.
//c#中使用指针:在需要使用指针的地方 加 unsafe
137.
138.
//unsigned char对应public byte
139.
/*
140.
* typedef void (*CALLBACKFUN1W)(wchar_t*, void* pArg);
141.
* typedef void (*CALLBACKFUN1A)(char*, void* pArg);
142.
* bool BIOPRINT_SENSOR_API dllFun1(CALLBACKFUN1 pCallbackFun1, void* pArg);
143.
* 调用方式為
144.
* [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
145.
* public delegate void CallbackFunc1([MarshalAs(UnmanagedType.LPWStr)] StringBuilder strName, IntPtr pArg);
146.
*
147.
*
148.
*/