会搭讪的饭盒 · 删掉Godot C#版本后出现的包引用问题 - · 3 周前 · |
聪明伶俐的肉夹馍 · 2019南航与英国伦敦城市大学自动化(航空电 ...· 1 月前 · |
讲道义的脸盆 · 哪些人的婚姻容易出现第三者呢?_网易订阅· 7 月前 · |
有腹肌的烤红薯 · 抱歉我拿了女主角的剧本漫画 - 抖音· 1 年前 · |
冷静的萝卜 · 娱乐圈的“人情冷暖”,在章子怡身上体现得淋漓 ...· 1 年前 · |
傻傻的消炎药 · 成都车展|近距离体验新款宝马iX3 ...· 1 年前 · |
原创文章,欢迎转载。转载请注明:转载自 祥的博客
原文链接: http://blog.csdn.net/humanking7/article/details/50981922
作用 |
C++类型 |
位数[Bytes] |
C#类型 |
别名 |
取值范围 |
后缀 |
---|---|---|---|---|---|---|
字符 |
char |
1 |
sbyte |
System.SByte |
-128~127 |
|
字符(u) |
unsigned char |
1 |
byte |
System.Byte |
0~255 |
|
宽字符 |
wchar_t |
2 |
char |
System.Char |
|
|
宽字符(无符号) |
unsigned wchar_t |
2 |
|
|
|
|
逻辑值 |
bool |
1 |
bool |
System.Boolean |
true,false |
|
短整数 |
short |
2 |
short |
System.Int16 |
-32,768 ~ 32,767 |
|
短整数(无符号) |
unsigned short |
2 |
ushort |
System.UInt16 |
0~65535(2的16次方) |
|
整数 |
int |
4 |
int |
System.Int32 |
-2,147,483,648 ~ 2,147,483,647 |
|
整数(无符号) |
unsigned int |
4 |
uint |
System.UInt32 |
0 ~ 4,294,967,295 |
|
长整型 |
long |
8 |
long |
System.Int64 |
-9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 |
L (最好用大写,因为小写l容易与1混淆) |
长整型(无符号) |
unsigned long |
8 |
ulong |
System.UInt64 |
0 ~ 18,446,744,073,709,551,615 |
|
单精度实数 |
float |
4 |
float |
System.Single |
-3.402823e38 ~ 3.402823e38 |
|
双精度实数 |
double |
8 |
double |
System.Double |
-1.79769313486232e308 ~ 1.79769313486232e308 |
d |
长双精度实数 |
long double |
10 |
decimal |
System.Decimal |
-79228162514264337593543950335 ~ 79228162514264337593543950335 |
m |
字符串 |
string |
|
string |
System.String |
|
|
对象 |
object |
|
|
System.Object |
|
|
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 变量名 |
char 变量名 |
byte 变量名 //C++中一个字符用一个字节表示,C#中一个字符用两个字节表示 |
char 数组名[数组大小] |
MarshalAs(UnmanagedType.ByValTStr, SizeConst = 数组大小)] public string 数组名; ushort |
char * |
string //传入参数 |
char * |
StringBuilder//传出参数 |
char *变量名 |
ref string 变量名 |
char *输入变量名 |
string 输入变量名 |
char *输出变量名 |
[MarshalAs(UnmanagedType.LPStr)] StringBuilder 输出变量名 |
char ** |
string |
char **变量名 |
ref string 变量名 |
const char * |
string |
char[] |
string |
char 变量名[数组大小] |
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=数组大小)] public string 变量名 |
struct 结构体名 *变量名 |
ref 结构体名 变量名 |
委托 变量名 |
委托 变量名 |
int |
int |
int |
ref int |
int & |
ref int |
int * |
ref int //C#中调用前需定义int 变量名 = 0; |
*int |
IntPtr |
int32 PIPTR * |
int32[] |
float PIPTR * |
float[] |
double** 数组名 |
ref double 数组名 |
double*[] 数组名 |
ref double 数组名 |
long |
int |
ulong |
int |
UINT8 * |
ref byte //C#中调用前需定义byte 变量名 = new byte(); |
handle |
IntPtr |
hwnd |
IntPtr |
void * |
IntPtr |
void * user_obj_param |
IntPtr user_obj_param |
void * 对象名称 |
([MarshalAs(UnmanagedType.AsAny)]Object 对象名称 |
char, INT8, SBYTE, CHAR |
System.SByte |
short, short int, INT16, SHORT |
System.Int16 |
int, long, long int, INT32, LONG32, BOOL , INT |
System.Int32 |
__int64, INT64, LONGLONG |
System.Int64 |
unsigned char, UINT8, UCHAR , BYTE |
System.Byte |
unsigned short, UINT16, USHORT, WORD, ATOM, WCHAR , __wchar_t |
System.UInt16 |
unsigned, unsigned int, UINT32, ULONG32, DWORD32, ULONG, DWORD, UINT |
System.UInt32 |
unsigned __int64, UINT64, DWORDLONG, ULONGLONG |
System.UInt64 |
float, FLOAT |
System.Single |
double, long double, DOUBLE |
System.Double |
char*
的操作c++:
char*
对应 c#:
StringBuilder
typedef void (*CALLBACKFUN1W)(wchar_t*, void* pArg);
typedef void (*CALLBACKFUN1A)(char*, void* pArg);
bool BIOPRINT_SENSOR_API dllFun1(CALLBACKFUN1 pCallbackFun1, void* pArg);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void CallbackFunc1([MarshalAs(UnmanagedType.LPWStr)] StringBuilder strName, IntPtr pArg);
会搭讪的饭盒 · 删掉Godot C#版本后出现的包引用问题 - 3 周前 |
讲道义的脸盆 · 哪些人的婚姻容易出现第三者呢?_网易订阅 7 月前 |
有腹肌的烤红薯 · 抱歉我拿了女主角的剧本漫画 - 抖音 1 年前 |