0

I've searched everywhere and can't seem to find the answer. Nobody has made anything like this apparently. I'm trying to get input from a user.

while(!done)
{
    PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE);
    if (msg.message == WM_QUIT) {
        done = true; //if found, quit app
    } else if (msg.message == WM_KEYDOWN) {
        game->KeyDown(msg.wParam);
    } else if (msg.message == WM_KEYUP) {
        game->KeyUp(msg.wParam);
    } else {
        /*  Translate and dispatch to event queue*/
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
return msg.wParam;

When I run it it gives me the error:

error LNK2019: unresolved external symbol "public: void __thiscall Game::KeyDown(unsigned int &)" (?KeyDown@Game@@QAEXAAI@Z) referenced in function _WinMain@16

I have everything defined in the header of the game class... It's subsystem is set to nothing, but the "(/SUBSYSTEM:WINDOWS)" works..

1 Answers1

4

Piece of cake. "unresolved external symbol" most commonly means you declared a function without specifying what it does. Consider the following example:

void undefined();
void LNK2019()
{
   undefined(); //the offending line
}
void main()
{
    //doesn't even have to do anything; it's not a runtime error
}

The function LNK2019() calls undefined(), but you never told undefined() what to do. Your linker doesn't know what to make of the line. In your specific case, I'm betting Game::KeyDown doesn't have a body.

A few other comments on your code:

  1. For Windows messages, avoid if-else trees; use switch-case. It's commonly faster, and definitely more readable.

  2. I've never seen messages handled in a loop like that. Your Windows Procedure (whose function is commonly shortened to WndProc) should handle all Windows messages - the entire purpose of DispatchMessage is to send messages to that function.

Proxy
  • 1,824
  • 1
  • 16
  • 27