Daniel_laksjdhfg

i get this error:

Error 1 error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR' c:\hfscontrol\hfscontrol\hfscontrol.cpp 80

when using this code:

// Create Button

hwndButton = CreateWindowEx(0,"BUTTON","&ClickMe",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,20,20,100,50,hWnd,NULL,hInstance,NULL);

could anyone let me know what is wrong this is a plain win32 project created in VS2005.

thanks in advance,

Daniel



Re: Visual C++ Language easy win32 :)

Jonathan Caves - MSFT

You are compiling with Unicode enabled (which is good) but you are still using narrow strings. I would change the code to:

CreateWindowEx(0, _T("BUTTON"), _T("&ClickMe"), WS_ ...

This will make the strings Unicode/ASCII agnostic. Note: you may need to include tchar.h in order to get the definition of _T






Re: Visual C++ Language easy win32 :)

Chuck the Code Monkey

This is answered in the very top thread in the forum:

" FAQ: Cannot convert from 'const char [..]' to 'LPCTSTR'"
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=849851&SiteID=1

It also mentions your error involving LPCSWTR as well.





Re: Visual C++ Language easy win32 :)

Sarath.

Use _T(x) macro (x is the string) which will differentiate the string definition based on UNICODE or NON-UNICODE builds.

to specify a constant wchar* (LPCWSTR) you have to prefix L before string

i.e L"Test";

_T will prefix L before the string if unicode enabled.

Use TCHAR pointers instead of char* pointers if you are using UNICODE. because TCHAR will behave accordinggly based on the build environment.






Re: Visual C++ Language easy win32 :)

TilakGopi

Hi,

make it like

HWND hwndButton = CreateWindowEx(0,_T("BUTTON"),_T"&ClickMe"),WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,20,20,100,50,hWnd,NULL,hInstance,NULL);

Thanx,

Ch.T.Gopi Kumar.