Hey,

I just started to learn how to program in Windows and have a problem with the very first program. It's from a C Book I have, so i guess the code is alright.

Error: undefined reference to `_Z7WndProcP6HWND__jjl@16'

I'm using the Eclipse C/C++ IDE; libraries (gdi32.lib) are linked, -mwindows is set.

Whats the problem? Thanks in advance!

[cpp]#include <windows.h>
// Globale Variablen
HINSTANCE hInst  	= 0;		// Programm-Handle
char szAppName[] 	= "Basis"; 	// Name der Anwendung
char szTitle[100]	= "Hallo Windows";	// Fenstertitel


	
// Prototypen eigener Funktionen
	
BOOL InitApplication();
BOOL InitInstance(int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

// Der Programm Einstiegspunkt
int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPSTR	  lpCmdLine,
					int		  nCmdShow)
{
	MSG msg;				// Platz für eine Message
	hInst = hInstance; 		// Handle der Instanz an eine globale Variable zuweisen
	if(!InitApplication())	// Fenster registrieren
		return FALSE;
	if(!InitInstance(nCmdShow))	// Hauptfenster erzeugen
		return FALSE;
	while(GetMessage(&msg,NULL,0,0)) //Meldungsschleife
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return (msg.wParam);
}

//--------------------Fortsetzung----------------------

BOOL InitApplication()
{
	WNDCLASSEX wc;							//Fensterklasse
	
//Die Eigenschaften der Fensterklasse festlegen:
	
	wc.cbSize 	= sizeof(WNDCLASSEX);								//Anzahl Byte dieser Struktur
	wc.style 			= CS_HREDRAW | CS_VREDRAW;				// Fensterstile
	wc.lpfnWndProc 		= (WNDPROC) WndProc;						// Fensterprozedur
	wc.cbClsExtra 		= 0;									//Hier kann zusätzlicher Speicher reserviert werden
	wc.cbWndExtra 		= 0;									//den das Programm für eigene Zwecke nutzt.
	wc.hInstance 		= hInst;								//Handle dieser Instanz											
	wc.hIcon			= LoadIcon( NULL, IDI_APPLICATION); 	//Standard Icon
	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Standard Cursor Pfeil
	wc.hbrBackground	= (HBRUSH)GetStockObject(WHITE_BRUSH); 	//Hintergrund der Client Area
	wc.lpszMenuName 	= NULL;
	wc.lpszClassName	= szAppName;
	wc.hIconSm 			= LoadIcon( NULL, IDI_APPLICATION);
	
	return RegisterClassEx(&wc);
}

BOOL InitInstance(int nCmdShow)
{
	HWND hWnd;
	hWnd = CreateWindow(
				szAppName,		 		//Name der Fensterklasse
				szTitle,				//Titel des Fensters
				WS_OVERLAPPEDWINDOW,	//Fensterstil //Lage des Fensters:					
				CW_USEDEFAULT,			//x-Koordinate
				0,						//y-Koordinate
				CW_USEDEFAULT,			//Fensterbreite
				0,						//Fensterhöhe
				NULL,					//Handle: Elternfenster
				NULL,					//Handle: Menue
				hInst,					//Handle des Programms
			NULL);					//Zeiger auf zusätzliche Daten
	if( !hWnd)
		return (FALSE);
	ShowWindow(hWnd, nCmdShow);		//Fenster anzeigen.
	UpdateWindow(hWnd);				//WM_PAINT-Meldung
	return(TRUE);
}

InitApplication() references a function names WinProc. You have to add that function to your program before it will link successfully. That function will probably be explained a little further on in your book, or you can study this tutorial.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.