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()