0
#ifndef UNICODE
#define UNICODE
#endif

#include <windows.h>

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int     nCmdShow)
{

const wchar_t CLASS_NAME[]  = L"Sample Window Class";

WNDCLASS wc = { };

wc.lpfnWndProc   = WindowProc;
wc.hInstance     = hInstance;
wc.lpszClassName = CLASS_NAME;

RegisterClass(&wc);



HWND hwnd = CreateWindowEx(
    0,
    CLASS_NAME,
    L"Learn to Program Windows",
    WS_OVERLAPPEDWINDOW,


    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

    NULL,
    NULL,
    hInstance,
    NULL
    );

if (hwnd == NULL)
{
    return 0;
}

ShowWindow(hwnd, nCmdShow);



MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}

return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    return 0;

case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hdc = BeginPaint(hwnd, &ps);

        FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));

        EndPaint(hwnd, &ps);
    }
    return 0;

}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

This is the code, which is also the standard example you can find in the microsoft website that teach people how to program windows. http://msdn.microsoft.com/en-us/library/windows/desktop/ff381409(v=vs.85).aspx

The problem I receive is the following whenever I try to compile this code in codeblocks.

undefined reference to 'WinMain@16'

What is that and what can I do to compile and run this piece of code?

Paolo Caponeri
  • 127
  • 4
  • 15

1 Answers1

1

It seems strange to me that WinMain is called wWinMain: evidently you need a function called WinMain.

Oh, wait, you are using codeblocks? Probably wWinMain is specific of visual studio. Codeblocks wants the standard WinMain.

lunadir
  • 339
  • 3
  • 15
  • Yep that was it. By changing it from int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) to int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) Thank you :) – Paolo Caponeri May 31 '13 at 18:50
  • È il problema microsoft: gli standard. – lunadir May 31 '13 at 18:53
  • Come fai a sapere che io sia italiano? O.O Comunque non posso votarti la risposta perchè mi mancano 2di reputazione per votare. Grazie comunque però :) – Paolo Caponeri May 31 '13 at 20:51