Sign in to follow this  
A_B

function pointer

Recommended Posts

A_B    122
Hi, I wanted to pass a function pointer of an imput funcion to a window class which contains the window procedure. The class:
class cOpenGLLib
{
private:
        ...
	//the window procedure
	static LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
	//The external function that determines what to do with input
	static void (*inputFunc)();
        ...
public:
        //The function to which a function pointer is passed
        void MakeWindow(void (&inputFunction)(void));
};


In the cpp file:
//THE WINDOW PROCEDURE---------------------------------------------------------------------------//
LRESULT CALLBACK cOpenGLLib::WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	inputFunc();
	
	return DefWindowProc(hWnd, message, wParam, lParam);	
}
//define the input function
static void *(cOpenGLLib::*inputFunc)();


void cOpenGLLib::MakeWindow(void(&inputFunction)(void))
{
	//pass the iputfunction to the class' private input function
	inputFunc = inputFunction;
        ...
}

In the main.cpp file:
cOpenGLLib cOGL = cOpenGLLib::getInstance();

//input function
void input()
{
	switch (cOGL.msg.message)
	{
	case WM_KEYDOWN:
		PostMessage(cOGL.hWnd, WM_DESTROY, 0, 0);
		break;
	}
}

int WINAPI WinMain(...)
{
	void (*inputpntr)();
	inputpntr = &input;
	cOGL.MakeWindow(*inputpntr);
        ...
}


I compile the class to a lib file, which has no errors, but when i try to compile the main.cpp file, I get an unresolved external symbol for the inputFunc()
OGLL.lib(OGLL.obj) : error LNK2001: unresolved external symbol "private: static void (__cdecl* cOpenGLLib::inputFunc)(void)" (?inputFunc@cOpenGLLib@@0P6AXXZA)


Share this post


Link to post
Share on other sites
A_B    122
Thx for the help.
Changed that but I still get the same error, you really got my hopes up by spotting that one though :D.

Thanks
Alex

Share this post


Link to post
Share on other sites
Gage64    1235
Not sure, but try changing this:

//define the input function
static void *(cOpenGLLib::*inputFunc)();


to:

void (* cOpenGLLib::inputFunc)();

EDIT: Made a correction.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this