Whenever I try to compile a program with UNICODE defined I get the following error: "D:\Code-Blocks\lib/libmingw32.a(main.o):main.c:(.text+0x106): undefined reference to `WinMain@16".
The fact is that WinMain is defined and the code compiles well when I don't define UNICODE. Have I done something wrong or is it something related with MINGW32 (doesn't support UNICODE ?) ?
#define UNICODE 1
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
TCHAR szClassName[] = TEXT("Win32App");
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR CmdLine, int CmdShow)
{
HWND hWnd;
MSG msg;
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(wc));
wc.hInstance = hInstance;
wc.lpszClassName = szClassName;
wc.lpfnWndProc = WndProc;
wc.style = CS_DBLCLKS;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.cbSize = sizeof(WNDCLASSEX);
wc.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
if(!RegisterClassEx(&wc))
return 0;
hWnd = CreateWindowEx(
0,
szClassName,
TEXT("Sample"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, CmdShow);
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}