1. System::String 转换到 const wchar_t*
const wchar_t* ToUnmanagedUnicode( System::String^ str )
{
pin_ptr<const WCHAR> nativeString1 = PtrToStringChars( str );
return (const wchar_t*)nativeString1;
}
2. const wchar_t* / const char* 转换到 System::String
const wchar_t* p= L"hello";
System::String( p ).ToString();
3. C++数值类型转CLR数值类型
int a;
System::Int32 b = System::Int32( a );
4. HWND 转为IWin32Window
public ref class WindowWrapper : System::Windows::Forms::IWin32Window
{
public: WindowWrapper(IntPtr handle)
{
_hwnd = handle;
}
public:
property IntPtr Handle
{
virtual IntPtr get(void){return _hwnd;};
};
private: IntPtr _hwnd;
};
HWND nativehwnd;
IWin32Window^ w = gcnew Managed::WindowWrapper( System::IntPtr( nativehwnd ) );