Unable to identify errors

When I try to compile this program I get three errors that
I cannot identify. Please, help.

#include <windows.h>

LPCTSTR ClsName = L"BasicApp";
LPCTSTR WndName = L"A Simple Window";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
LPSTR lpCmdLine, int nCmdShow)
{
MSG Msg;
HWND hWnd;
WNDCLASSEX WndClsEx;

// Create the application window
WndClsEx.cbSize = sizeof(WNDCLASSEX);
WndClsEx.style = CS_HREDRAW | CS_VREDRAW;
WndClsEx.lpfnWndProc = WndProcedure;
WndClsEx.cbClsExtra = 0;
WndClsEx.cbWndExtra = 0;
WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClsEx.lpszMenuName = NULL;
WndClsEx.lpszClassName = ClsName;
WndClsEx.hInstance = hInstance;
WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

// Register the application
RegisterClassEx(&WndClsEx);

// Create the window object
hWnd = CreateWindow(ClsName,
WndName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);


// Find out if the window was created
if( !hWnd ) // If the window was not created,
return 0; // stop the application

// Display the window to the user
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);

// Decode and treat the messages
// as long as the application is running
while( GetMessage(&Msg, NULL, 0, 0) )
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

return Msg.wParam;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
// If the user wants to close the application
case WM_DESTROY:
// then close it
PostQuitMessage(WM_QUIT);
break;
default:
// Process the left-over messages
return DefWindowProc(hWnd, Msg, wParam, lParam);
}
// If something was not done, let it go
return 0;
}
When I try to compile this program I get three errors that
I cannot identify.

If you want help with compilation errors, it would behoove you to supply said errors.

You're missing a comma in your WinMain parameter list.

LPCTSTR ClsName = L"BasicApp";
These types don't agree.
Sorry, I'm a newbi and don't understand "these types don't agree". Why?
I've seen other similar examples and they work. Please, explain with an example.
Thank you very much.
Sorry, I'm a newbi and don't understand "these types don't agree".

It depends on the Character Set. If you use Multi Byte then LPCTSTR is not compatible with L"BasicApp", however it works when you use Unicode Character Set.
To learn more about the String types in Win32 have a look here:
http://www.codeproject.com/Articles/2995/The-Complete-Guide-to-C-Strings-Part-I-Win-Chara

If you add a comma after HINSTANCE hPrevInstance then it compiles with Unicode Character Set.

If you use Visual Studio you can set this in Project Properties->Configuration Properties->General->ProjectDefaults->Character Set.

Sorry, I'm a newbi and don't understand "these types don't agree". Why?

The proper way to use a pointer to null terminated array of TCHAR is to use the TEXT macro to specify the character type:

1
2
LPCTSTR ClsName = TEXT("BasicApp");
LPCTSTR WndName = TEXT("A Simple Window");


It is simpler, IMO, to just stick to wide or narrow characters and not have the hassle.
Last edited on
Thank you very much, Thomas. I have already downloaded the Complete Guide you recommend and will start to read it soon. Thank you very much cire, I really appreciate your help.
Topic archived. No new replies allowed.