Hi,
I am trying to implement a global mouse hook. However i want to recieve the mouse messages to my app. I decided to implement a function in the dll that takes a function pointer to the callback proc in the apps code.
My question is can you pass function pointers to a dll and if the answer is yes to that then can you see anything wrong with the following code.
Thanks in advance.
"Programmers are tools for converting caffeine into code - BSRF"
I am trying to implement a global mouse hook. However i want to recieve the mouse messages to my app. I decided to implement a function in the dll that takes a function pointer to the callback proc in the apps code.
My question is can you pass function pointers to a dll and if the answer is yes to that then can you see anything wrong with the following code.
Code:
// Dll code
typedef LRESULT (CALLBACK* HOOKCALLBACKPTR)(int code, WPARAM wParam, LPARAM lParam, int idHook);
HOOKCALLBACKPTR pAppHookCallback = NULL;
HHOOK hMouse = NULL;
// Initialise the CALLBACK and Mouse Hook
DLLEXPORT BOOL SetAutoScrollCallback(HOOKCALLBACKPTR P)
{
pAppHookCallback = P;
if (NULL == (hMouse = SetWindowsHookEx(WH_MOUSE,(HOOKPROC)MouseProc,hInstance,0)))
return FALSE;
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
pAppHookCallback(nCode,wParam,lParam,WH_MOUSE);
return CallNextHookEx(hMouse,nCode,wParam,lParam);
}
// Application.cpp
typedef LRESULT (CALLBACK* HOOKCALLBACKPTR)(int code, WPARAM wParam, LPARAM lParam, int idHook); // where idHook is the id of the calling hook (there could be more than one)
LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam,int idHook)
{
\\ TRACE("mouse hook here");
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
if (!SetAutoScrollCallback(HookProc))
return 0;
}
Thanks in advance.
"Programmers are tools for converting caffeine into code - BSRF"