Sign in to follow this  

function pointer

This topic is 2814 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, 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
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
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

This topic is 2814 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.

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