Click to See Complete Forum and Search --> : String conversion in Debug mode?


xeno33
March 28th, 2005, 07:06 PM
Hi all,

i'm currently using GDI+ with VC++ 6. Previously i was compiling in unicode but now i need to compile in the normal Win 32 Debug mode.

An error occured while compiling the construction of my Bitmap object:

// Contruct a Bitmap object based on a file
Bitmap bitmap(strFilePath);
strFilePath is my function parameter of type CString.

The error was:

error C2664: '__thiscall Gdiplus::Bitmap::Gdiplus::Bitmap(const unsigned short *,int)' : cannot convert parameter 1 from 'class CString' to 'const unsigned short *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

The syntax for the constructor that i'm using is :

Bitmap (const WCHAR *filename, BOOL useIcm);
The second parameter is optional and i do not require it's use.

Any way to solve this? Or do i have to use another constructor because WCHAR is a unicode type?

Appreciate any help or comments on the matter. :)

tmecham
March 28th, 2005, 07:15 PM
Try this:

CString str = "mybitmap.bmp" ;
LPWSTR lpszW = new WCHAR[255];
LPTSTR lpStr = str.GetBuffer( str.GetLength() );
int nLen = MultiByteToWideChar(CP_ACP, 0,lpStr, -1, NULL, NULL);
MultiByteToWideChar(CP_ACP, 0, lpStr, -1, lpszW, nLen);
Gdiplus::Bitmap *bitmap = new Gdiplus::Bitmap( lpszW );
delete[] lpszW;

GL

Andreas Masur
March 29th, 2005, 03:24 AM
[ Moved thread ]