0

I keep getting the following error when I try to compile my very simple program:

undefined reference to WindowProc(HWND__*, unsigned int, unsigned int, long)@16'

I don't see the problem and it's driving me crazy!

#include <iostream>
#include <windows.h>

using namespace std;

int sizeX = 500;
int sizeY = 500;

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

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain(
                   HINSTANCE hThisInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpszArgument,
                   int nFunsterStil
                   )
{
    HWND hwnd;
    MSG messages;
    WNDCLASSEX wincl;

    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProc;
    wincl.style = CS_DBLCLKS;
    wincl.cbSize = sizeof(WNDCLASSEX);`

    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;

    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    if(!RegisterClassEx(&wincl))
        return 0;

    hwnd = CreateWindowEx(
                          0,
                          szClassName,
                          "Windows App",
                          WS_SYSMENU,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          sizeX,
                          sizeY,
                          HWND_DESKTOP,
                          NULL,
                          hThisInstance,
                          NULL
                      );
}

What is wrong with the code?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Diriector_Doc
  • 582
  • 1
  • 12
  • 28

1 Answers1

1

You did not provide a definition for WindowProc(). You declared it, and assigned it to your WNDCLASSEX, now you have to actually implement its body, eg:

#include <iostream>
#include <windows.h>

using namespace std;

int sizeX = 500;
int sizeY = 500;

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

const char szClassName[ ] = "WindowsApp";

int WINAPI WinMain(
                   HINSTANCE hThisInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpszArgument,
                   int nFunsterStil
                   )
{
    HWND hwnd;
    MSG messages;
    WNDCLASSEX wincl;

    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProc;
    wincl.style = CS_DBLCLKS;
    wincl.cbSize = sizeof(WNDCLASSEX);`

    wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;

    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    if(!RegisterClassEx(&wincl))
        return 0;

    hwnd = CreateWindowEx(
                          0,
                          szClassName,
                          "Windows App",
                          WS_SYSMENU,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          sizeX,
                          sizeY,
                          HWND_DESKTOP,
                          NULL,
                          hThisInstance,
                          NULL
                      );

    // message loop here ...

    return 0;
}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    // your code here ...

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

See MSDN's documentation for more details:

Window Procedures

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Christopher Pisz
  • 3,757
  • 4
  • 29
  • 65