john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

win msg box wince

error cannot convert from 'const char' to 'LPCTSTR' or char* to 'sont WCHAR*'

This error message means that you are trying to pass a multi-byte string (const char [12]) to a function which expects a unicode string (LPCTSTR).

The LPCTSTR type extends to const TCHAR*, where TCHAR is char when you compile for multi-byte and wchar_t for unicode.

Since the compiler doesn't accept the char array, we can safely assume that the actual type of TCHAR, in this compilation, is wchar_t.

prefixing it with L, such as L"Hello world!"

_T("Hello world!")

this is a generic macro, latter will expand to the L prefix if you are compiling for unicode

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <aygshell.h>

int APIENTRY WinMain( 
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow )
{
        MessageBox(NULL, L"I Love Bobby", L"IMPORTANT TITLE", MB_OK);
        return 0;
}

  • « file remove linefeed characters
  • Apache require group »

Published

Feb 6, 2010

Category

c

~139 words

Tags

  • box 3
  • msg 2
  • win 19
  • win-ce 40
  • wince 4