Cannot convert const char to lpcwstr


#include <windows.h>

#include

<tchar.h>

#include

<winuser.h>

const

TCHAR sai_classname[]= TEXT("saiwindowcls");

LRESULT CALLBACK wndproc(HWND hwnd, UINT m1,WPARAM wparam, LPARAM lparam)

{

switch

(m1)

{

case

WM_CLOSE: DestroyWindow(hwnd);

break

;

case

WM_DESTROY: PostQuitMessage(0);

break

;

default

: return DefWindowProc(hwnd, m1, wparam, lparam);

}

return

0 ;

}

int

WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)

{

//sai1 is the object of wndclassex structure

WNDCLASSEX sai1;

HWND hwnd;

MSG msg;

//registering class

sai1.cbSize = sizeof(WNDCLASSEX);

sai1.style = 0;

sai1.lpfnWndProc = wndproc;

sai1.cbWndExtra = 0;

sai1.cbClsExtra = 0;

sai1.hbrBackground = (HBRUSH)(COLOR_BACKGROUND,COLOR_MENU +2);

sai1.hCursor = LoadCursor(NULL,IDC_ARROW);

sai1.hIcon =LoadIcon(NULL,IDI_APPLICATION);

sai1.hInstance = hInstance;

sai1.lpszClassName = sai_classname;

sai1.lpszMenuName = NULL;

sai1.hIcon = LoadIcon(NULL,IDI_APPLICATION);

if (!RegisterClassEx( &sai1))

{

MessageBox(NULL,L"Unable To Register",L"HAZARD", MB_ICONERROR);

return

0 ;

}

//Creating window

hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,sai_classname,L

"Sai Window",

WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,900,600,

NULL,NULL,hInstance,NULL);

if

(hwnd == NULL)

{

MessageBox(NULL,L

"window creation failes",L"BUMP",MB_ICONHAND);

return

0 ;

}

Notice the above code would not execute if you declare the following code as and get error message as "cannot convert const char to lpcwstr"

Above is the solution for the error message and below is the possible mistakes.

 

const CHAR sai_classname[]= "saiwindowcls";

"window creation failes", ( here you should declare either _T(x) or L "string")

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s