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

相关文章:

  • 2021-05-31
  • 2022-12-23
  • 2021-12-12
  • 2021-12-16
  • 2022-12-23
  • 2021-06-25
  • 2021-11-16
  • 2021-12-08
猜你喜欢
  • 2021-09-17
  • 2022-02-07
  • 2021-12-04
  • 2022-02-08
  • 2021-10-22
  • 2022-12-23
相关资源
相似解决方案