-1

I'm having an issue where the following code can't be compiled using CL (VS CMD). Instead of Compiling, it gives me Error LN2019. Compiling the same Code inside VS, compiles without errors.

#include <windows.h>

LRESULT CALLBACK
MainWindowCallback( HWND   Window,
                    UINT   Message,
                    WPARAM WParam,
                    LPARAM LParam)
{
    LRESULT Result = 0;

    switch(Message)
    {
        case WM_SIZE:
        {
            OutputDebugStringA("WM_SIZE\n");
        } break;

        case WM_DESTROY:
        {
            OutputDebugStringA("WM_DESTROY\n");
        } break;

        case WM_CLOSE:
        {
            OutputDebugStringA("WM_CLOSE\n");
        } break;

        case WM_ACTIVATEAPP:
        {
            OutputDebugStringA("WM_ACTIVATEAPP\n");
        } break;

        default:
        {
            // OutputDebugSTringA("default\n")
            Result = DefWindowProc(Window, Message, WParam, LParam);
        } break;
    }

    return(Result);
}

int CALLBACK
WinMain(HINSTANCE Instance,
        HINSTANCE PrevInstance,
        LPSTR     CommandLine,
        int       ShowCode)
{
    WNDCLASS WindowClass = {};

    WindowClass.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
    WindowClass.lpfnWndProc = MainWindowCallback;
    WindowClass.hInstance = Instance;
    // WindowClass.hIcon;
    WindowClass.lpszClassName = "FooWindowClass";

    return(0);
}

I tracked down the issue to Line 36:

Result = DefWindowProc(Window, Message, WParam, LParam);

When i comment this line out, the file compiles just fine. The cl command used to Compile is also pretty standard:

cl -Zi Foo.cpp

Is there some cl parameter i missed?

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
kazaamjt
  • 121
  • 1
  • 7

2 Answers2

0

You must link with user32.lib:

cl Foo.cpp user32.lib
mikedu95
  • 1,725
  • 2
  • 12
  • 24
  • Yes, this did it. Figured it would be a parameter like that. Any idea why it wouldn't automatically include user32.lib when using cl? Unlike in VS itself? – kazaamjt Jan 11 '16 at 15:57
  • @kazaamjt: Visual Studio doesn't automatically include any arguments to CL either. It uses those **you** specified in the project settings. – IInspectable Jan 12 '16 at 01:08
-1

Error Error LN2019 is not having a "main" (you seem to have named it WinMain).

See also: error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

Community
  • 1
  • 1
John Hascall
  • 9,176
  • 6
  • 48
  • 72