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)