Author Topic: Unicode problem  (Read 4102 times)

webspy

  • Guest
Unicode problem
« on: October 06, 2006, 10:35:04 pm »
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 ?) ?

Here's the code I'm trying to compile:

Code
#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;
}

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Unicode problem
« Reply #1 on: October 06, 2006, 11:13:19 pm »
You may want to define _UNICODE, not UNICODE. Also, you might want to try wWinMain.

http://www.i18nguy.com/unicode/c-unicode.html
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."