MtRock.cs Paradise 16

Qingshuan’s Programming Blog

Archive for February 12th, 2008

[C++/.NET] Conversion from System::String ^ to CString

Posted by linuxprogram on February 12, 2008

For conversion from System::String to CString:

Most Efficient:

using
namespace System::Runtime::InteropServices;

System::String^ str = “A test string.”;

char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(str);

CString target = str2;

Marshal::FreeHGlobal((IntPtr)str2);

Simplest but least Efficient

CString target2 = CString(str);

Posted in C/C++/C# | Leave a Comment »

[C++/.NET] Conversion between System::Drawing::Bitmap & CBitmap, HBITMAP

Posted by linuxprogram on February 12, 2008

Conversion from System::Drawing::Bitmap to CBitmap:

 
 

System::Drawing::Bigmap^ bmp = gcnew System::Drawing::Bigmap(filename);

 
 

HBITMAP hBmp = (HBITMAP)bmp->GetHbitmap().ToInt32();

CBitmap Bitmap;

Bitmap.Attach(hBmp);

 

And the Reverse:

System::Drawing::Bitmap::FromHbitmap(System::IntPtr(HBITMAP hbmp));

Posted in C/C++/C# | Leave a Comment »