static_cast<type-id>(expression) 演算子を使います。
enum TestEnum{
A, B
};
int main(array<System::String^> ^args){
int n = static_cast<int>(A);
return 0;
}
バイト配列の変換
ネイティブ関数にマネージバイト配列を渡す一般的な方法です。マネージバイト配列の実際のデータの内部表現は、ネイティブバイト配列と同じであることが、C++/CLIの仕様で保証されているので、マネージバイト配列の先頭バイトのポインタをネイティブ関数に渡せば良いということになるのだが、マネージバイト配列のデータの位置は、ガベレージコレクタによって、移動される可能性がある。このため、pin_ptr を使ってガベレージコレクタから移動されない固定されたポインタを取得して、これをネイティブ関数に渡す必要がある。
void nativeMethod(const unsigned char* pchar, int len);
int main(array<System::String^> ^args){
array<Byte>^ bs = gcnew array<Byte>(3);
pin_ptr<Byte> pchar = &bs[0];
nativeMethod(pchar, bs->Length);
return 0;
}
文字列の変換
ネイティブ型とマネージ型の文字列を相互に変換するには、通常、marshal_as 関数を使います。一部の変換では、marshal_context::marshal_as 関数が必要となります。
marshal_as
構文:
To_Type marshal_as( From_Type input );
サンプル:
const char* pChar = "const char String";
String^ str;
str = marshal_as( pChar );
marshal_context::marshal_as
構文:
To_Type marshal_as( From_Type input );
サンプル:
marshal_context^ context = gcnew marshal_context();
String^ str = gcnew String("managed string");
const char* pChar;
pChar = context->marshal_as( message );
delete context; // pCharが無効になる
対応表
変換前 | 変換後 | 関数またはクラス | Include |
---|---|---|---|
System::String^ | const char* | marshal_context | marshal.h |
const char* | System::String^ | marshal_as | marshal.h |
char* | System::String^ | marshal_as | marshal.h |
System::String^ | const wchar_t * | marshal_context | marshal.h |
const wchar_t * | System::String^ | marshal_as | marshal.h |
wchar_t* | System::String^ | marshal_as | marshal.h |
System::IntPtr | HANDLE | marshal_as | marshal_windows.h |
HANDLE | System::IntPtr | marshal_as | marshal_windows.h |
System::String^ | BSTR | marshal_context | marshal_windows.h |
BSTR | System::String^ | marshal_as | marshal.h |
System::String^ | bstr_t | marshal_as | marshal_windows.h |
bstr_t | System::String^ | marshal_as | marshal_windows.h |
System::String^ | std::string | marshal_as | marshal_cppstd.h |
std::string | System::String^ | marshal_as | marshal_cppstd.h |
System::String^ | std::wstring | marshal_as | marshal_cppstd.h |
std::wstring | System::String^ | marshal_as | marshal_cppstd.h |
System::String^ | CStringT | marshal_as | marshal_atl.h |
CStringT | System::String^ | marshal_as | marshal_atl.h |
System::String^ | CStringT$ltwchar_t$gt | marshal_as | marshal_atl.h |
CStringT<wchar_t> | System::String^ | marshal_as | marshal_atl.h |
System::String^ | CComBSTR | marshal_as | marshal_atl.h |
CComBSTR | System::String^ | marshal_as | marshal_atl.h |
BetMGM Sportsbook Review and Bonus Code - Mapyro
返信削除BetMGM is a sportsbook that's become popular as the first to operate an online 구리 출장안마 casino. This casino 부산광역 출장안마 was launched in 사천 출장샵 2003, making BetMGM 당진 출장샵 the Rating: 4.3 김포 출장샵 · Review by Alex W · Price range: $$