Jump to content
  • Advertisement
Sign in to follow this  
garyfletcher

Win32 api help needed

This topic is 5008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all I'm just starting out with graphics and so I've got a book "Beginning Game Programming" and started to look at the quick Win32 primer. I know that everyone will tell me to use SDL but, unfortunately, I bought the book before I heard about SDL so thought I'd try it out. Anyway. I'm using DEV-C++ and I created a new Windows project so I thought (perhaps mistakenly) that all the necessary libaries would be used when compling and linking BUT I'm getting the following linker error: Compiler: Default compiler Building Makefile: "C:\beginning Win32 GP\Skeleton\Makefile.win" Executing make... make.exe -f "C:\beginning Win32 GP\Skeleton\Makefile.win" all g++.exe -c Skeleton.cpp -o Skeleton.o -I"include/c++/3.3.1/mingw32" -I"include/c++/3.3.1" -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include" -I"C:/Dev-Cpp/include/SDL" -I"." g++.exe Skeleton.o Skeleton_private.res -o "Skeleton.exe" -L"lib" -L"C:/Dev-Cpp/dll" -mwindows Skeleton.o(.text+0x19):Skeleton.cpp: undefined reference to `_Z7WndProcP6HWND__jjl@16' collect2: ld returned 1 exit status make.exe: *** [Skeleton.exe] Error 1 Execution terminated Does anyone know what's goign on? The source I'm trying to compile is pretty simple:

SKELLETON.H

// Header file for the Skeleton source
#ifndef __SKELETON_H
#define __SKELETON_H

//-----------------------------------------------------------------
// Include files
//-----------------------------------------------------------------
#include <windows.h>
#include "Resource.h"

#endif

SKELLETON.CPP

// Main Skeleton Source file

#include "Skeleton.h"

/*  Declare Windows procedure  */
LRESULT CALLBACK WndProc (HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    PSTR szCmdLine,
                    int iCmdShow)

{
	static TCHAR szAppName[] = TEXT("Skeleton");
    HWND hwnd;           /* This is the handle for our window */
    MSG msg;            	/* Here messages to the application are saved */
    WNDCLASSEX wndClass;    /* Data structure for the windowclass */

    /* The Window structure */
    wndClass.hInstance = hInstance;
    wndClass.lpszClassName = szAppName;
    wndClass.lpfnWndProc = WndProc;      /* This function is called by windows */
    wndClass.style = CS_HREDRAW | CS_VREDRAW;   /* Catch double-clicks */
    wndClass.cbSize = sizeof (wndClass);

    /* Use default icon and mouse-pointer */
    wndClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SKELETON));
    wndClass.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_SKELETON_SM));
    wndClass.hCursor = LoadCursor (NULL, IDC_ARROW);
    wndClass.lpszMenuName = NULL;                 /* No menu */
    wndClass.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wndClass.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wndClass))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szAppName,         /* Classname */
           szAppName,       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           CW_USEDEFAULT,                 /* The programs width */
           CW_USEDEFAULT,                 /* and height in pixels */
           NULL,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, iCmdShow);
    UpdateWindow(hwnd);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage(&msg, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&msg);
        /* Send message to WindowProcedure */
        DispatchMessage(&msg);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return (int)msg.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)                  /* handle the messages */
    {
		HDC hDC;
		PAINTSTRUCT ps;
		RECT rect;
		
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
            
        case WM_PAINT:
		{
			// Draw some text centred in the client area of the main window
			hDC = BeginPaint(hwnd,&ps);
			
			GetClientRect(hwnd,&rect);
			
			DrawText(hDC,TEXT("This is a Skeleton application!"), -1, &rect,
					 DT_SINGLELINE | DT_CENTER | DT_VCENTER);
					 
			EndPaint(hwnd,&ps);
		}
            
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, msg, wParam, lParam);
    }

    return 0;
}

RESOURCE.H

// Resourse header for Skeleton resources
#ifndef __RES_H
#define __RES_H

//----------------------------------------------------------
// Icons					Range : 1000 - 1999
//----------------------------------------------------------
#define IDI_SKELETON		1000
#define IDI_SKELETON_SM		1001

#endif

RESOURCE.RC:

// Skeleton Resource Source file

#include "Resource.h"

//----------------------------------------------------------
// Icons
//----------------------------------------------------------
IDI_SKELETON	ICON	"Res\\Icons\\Skeleton.ico"
IDI_SKELETON_SM	ICON	"Res\\Icons\\Skeleton_sm.ico"

Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
EDIT: DARN, too slow. Ignore this message

Your problem is that you have named the WndProc incorrectly.

At the beginning you define a window procedure called "WndProc" and tell windows that this function is what will handle all the windows messages.

Later on in the file when you come to declare your message handling function, you called the function "WindowProcedure". So this function isn't called by windows as it is not the same function as W"ndProc".

So in order to fix it simply change:

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)


To:

LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)


Hope this helps

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!