How to fix "undefined reference to 'WinMain@16'" problem?

So, I am messing around on the Windows Dev Center (http://msdn.microsoft.com/en-us/library/windows(dont have to click that)) and I wanted to see how they say to create a window, and I tried it and the debugger says: undefined reference to WinMan@16.

What does that mean?!?!? Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

#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, PWSTR pCmdLine, int nCmdShow)
{
    // Register the window class.
    const wchar_t CLASS_NAME[]  = L"Sample Window Class";

    WNDCLASS wc = { };

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

    RegisterClass(&wc);

    // Create the window.

    HWND hwnd = CreateWindowEx(
        0,                              // Optional window styles.
        CLASS_NAME,                     // Window class
        L"Learn to Program Windows",    // Window text
        WS_OVERLAPPEDWINDOW,            // Window style

        // Size and position
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

        NULL,       // Parent window
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data
        );

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

    ShowWindow(hwnd, nCmdShow);

    // Run the message loop.

    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);
}
You accidentally named your function wWinMain instead of WinMain, so your linker has no idea where to find the main entry point for your windows API application.
Well, I just changed it and it still says it. I cant find any other places where it is wrong. Any other suggestions?
PWSTR is also wrong... it's supposed to be LPSTR:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pCmdLine, int nCmdShow)
Actually, wWinMain (and the PWSTR thing too) work for unicode.
But then would he have to configure his linker to look for the wide entry point?
Alright, thanks everybody I fixed it. WinMain and LPSTR instead of wWinMain and etc. whatever, I will try and remember that for next time
Are you using MinGW, don't you ? If so, you should know that MinGW runtime does not implement wWinMain or wmain entry points.
YEaah I am. Where do I get MinGW Ru ntime? (or how...)
If you have MinGW, you already have the runtime.

He was just saying that the wWinMain doesn't work with MinGW... which is why you had to use WinMain instead.
Oh. Well that makes sense. I was wondering why they have two different compilers with the same name.... (basically same)
MinGW Runtime = The DLLs required for applications built with MinGW
MinGW = Tools to build applications made with MinGW (huh)

Same happens for any other compiler.

<x> Runtime = Requirements for running applications build with <x>
(Usually DLLs)
Topic archived. No new replies allowed.