How to convert LPWSTR to LPCSTR??

Jul 8, 2011 at 1:26am
Hello

I am trying to display a bitmap picture on a static text.

here is a code.

m_static.ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE);

HBITMAP hBmp = ::LoadBitmapA(AfxGetInstanceHandle(), MAKEINTRESOURCE((LPCSTR)IDB_BITMAP1)); <-- error line
m_static.SetBitmap(hBmp);

BITMAP size;
::GetObjectA(hBmp, sizeof(BITMAP), &size);

m_static.MoveWindow(0, 0, size.bmWidth, size.bmHeight);
m_static.ShowWindow(SW_SHOW);

then, the error message says "You can't convert LPWSTR to LPCSTR".

I don't know what to do. I need help T_T
Jul 8, 2011 at 1:31am
Change LoadBitmapA to LoadBitmap. Looks like you are compiling in UNICODE.
Jul 8, 2011 at 1:34am
Correct. MAKEINTRESOURCE gives you a TCHAR, so use the TCHAR version of the function (LoadBitmap).

Also, no need to cast there, MAKEINTRESOURCE does the casting:

 
::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));
Jul 8, 2011 at 1:35am
It works after using LoadBitmap instead of LoadBitMapA.
What if i wanted to use LoadBitmapA?? What should I do to make it work?
Jul 9, 2011 at 5:37pm
Then you'd use MAKEINTRESOURCEA() instead of MAKEINTRESOURCE
Topic archived. No new replies allowed.