Windows Phone Runtime Component 是Windows Phone 平台用来写C++类库的项目类型。c++
主要目的是让C#和C++进行互操做,引用历史的C++代码,保护知识产权,提供性能等。windows
这里要注意可能会涉及到多种类型系统,分别是:ide
C# | .net CLR | std c++ | c++/cx | windows runtime | win32 | Length |
bool | Boolean | bool | bool | Boolean | 1 | |
byte | Byte | char | char | Char | CHAR | 8 |
char | Char | __wchar_t | char16 | Char16 | wchar_t | 16 |
short | Int16 | short | int16 | Int16 | 16 | |
ushort | Int32 | unsigned short | uint16 | UInt16 | WORD | 16 |
int | Int32 | int | int | Int32 | 32 | |
uint | UInt32 | unsigned int | uint32 | UInt32 | DWORD | 32 |
long | Int64 | long long | int64 | Int64 | 64 | |
ulong | UInt64 | unsigned long long | uint64 | UInt64 | DWORD64 | 64 |
float | Single | float | float32 | Single | FLOAT | |
double | UInt64 | double | float64 | Double | ||
string | String | std:wstring, L"" | String^ | HSTRING | ||
最多见的是C++代码中的字符串都是单字节的,如 char等,而要与C#中的双字节字符串交互,就必须在单字节和双字节之间作转换。固然还有其余类型的转换。性能
wchar_t 到charui
DWORD nWLength = WideCharToMultiByte(CP_OEMCP, NULL, wchar_s, -1, NULL, 0, NULL, FALSE); char_s = new char[nWLength]; DWORD nCLength = WideCharToMultiByte(CP_OEMCP, NULL, wchar_s, -1, char_s, nWLength, NULL, FALSE);
char 到wchar_tspa
DWORD nWLength = MultiByteToWideChar(CP_ACP, 0, (LPCCH)char_s, -1, NULL, 0); wchar_t *pwValue = new wchar_t[nWLength]; DWORD nCLength = MultiByteToWideChar(CP_ACP, 0, (LPCCH)char_s, -1, pwValue, nWLength);
String^ 到 wchar_t*.net
String::Data()