{"id":1666,"date":"2022-08-30T15:18:26","date_gmt":"2022-08-30T15:18:26","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/27\/error-creating-a-window-in-windows-undefined-reference-to-winmain16-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:26","modified_gmt":"2022-08-30T15:18:26","slug":"error-creating-a-window-in-windows-undefined-reference-to-winmain16-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/error-creating-a-window-in-windows-undefined-reference-to-winmain16-collection-of-common-programming-errors\/","title":{"rendered":"Error creating a window in windows &ldquo;undefined reference to &#39;WinMain@16&#39;&rdquo;-Collection of common programming errors"},"content":{"rendered":"<pre><code>#ifndef UNICODE\n#define UNICODE\n#endif\n\n#include \n\nLRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);\n\nint WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int     nCmdShow)\n{\n\nconst wchar_t CLASS_NAME[]  = L\"Sample Window Class\";\n\nWNDCLASS wc = { };\n\nwc.lpfnWndProc   = WindowProc;\nwc.hInstance     = hInstance;\nwc.lpszClassName = CLASS_NAME;\n\nRegisterClass(&amp;wc);\n\n\n\nHWND hwnd = CreateWindowEx(\n    0,\n    CLASS_NAME,\n    L\"Learn to Program Windows\",\n    WS_OVERLAPPEDWINDOW,\n\n\n    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,\n\n    NULL,\n    NULL,\n    hInstance,\n    NULL\n    );\n\nif (hwnd == NULL)\n{\n    return 0;\n}\n\nShowWindow(hwnd, nCmdShow);\n\n\n\nMSG msg = { };\nwhile (GetMessage(&amp;msg, NULL, 0, 0))\n{\n    TranslateMessage(&amp;msg);\n    DispatchMessage(&amp;msg);\n}\n\nreturn 0;\n}\nLRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)\n{\n    switch (uMsg)\n    {\n    case WM_DESTROY:\n    PostQuitMessage(0);\n    return 0;\n\ncase WM_PAINT:\n    {\n        PAINTSTRUCT ps;\n        HDC hdc = BeginPaint(hwnd, &amp;ps);\n\n        FillRect(hdc, &amp;ps.rcPaint, (HBRUSH) (COLOR_WINDOW+1));\n\n        EndPaint(hwnd, &amp;ps);\n    }\n    return 0;\n\n}\nreturn DefWindowProc(hwnd, uMsg, wParam, lParam);\n}\n<\/code><\/pre>\n<p>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<\/p>\n<p>The problem I receive is the following whenever I try to compile this code in codeblocks.<\/p>\n<p>undefined reference to &#8216;WinMain@16&#8217;<\/p>\n<p>What is that and what can I do to compile and run this piece of code?<\/p>\n<ol>\n<li>\n<p>It seems strange to me that <code>WinMain<\/code> is called <code>wWinMain<\/code>: evidently you need a function called <code>WinMain<\/code>.<\/p>\n<p>Oh, wait, you are using codeblocks? Probably <code>wWinMain<\/code> is specific of visual studio. Codeblocks wants the standard <code>WinMain<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-27 12:26:14. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>#ifndef UNICODE #define UNICODE #endif #include 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&#8221;Sample Window Class&#8221;; WNDCLASS wc = { }; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = CLASS_NAME; RegisterClass(&amp;wc); HWND hwnd = CreateWindowEx( 0, CLASS_NAME, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1666","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1666","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1666"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1666\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}