Windows Message Hooks Problems 
Author Message
 Windows Message Hooks Problems

I'm trying to set a normal Windows Hook (of the type WH_CALLWNDPROC)

Anyway, I have declared a function inside a CWnd based class called
CDrawWnd like this:

DWORD FAR Pascal MyCallWndProc(int nCode, WPARAM wParam, LPARAM
lParam) {
        // For now, it doesn't matter what's in here - read below.

Quote:
}

Inside the function that Sets the Window Hook (which is the OnCreate
function of CDrawWnd), I tried to use the following code, but the
compiler comes back saying it can not type-cast from the current
function to the HOOKPROC type: (ProcInfo is a pre-defined structure of
PROCESS_INFORMATION filled by a call to ::CreateProcess).

hHook = ::SetWindowsHookEx(WH_CALLWNDPROC,
(HOOKPROC)CDrawWnd::MyCallWndProc, NULL, ProcInfo.dwThreadId)

I have even tried type-casting normal C-style function pointers like
this:

DWORD FAR PASCAL (*lpfn)(int, WPARAM, LPARAM);
lpfn = MyCallWndProc;

hHook = ::SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)lpfn, .....);

I have also tried it without the (HOOKPROC) type-cast.

Can anyone help?



Sun, 31 Dec 2000 03:00:00 GMT  
 Windows Message Hooks Problems

Quote:
>I tried to use the following code, but the
>compiler comes back saying it can not type-cast from the current
>function to the HOOKPROC type: (ProcInfo is a pre-defined structure of
>PROCESS_INFORMATION filled by a call to ::CreateProcess).

>hHook = ::SetWindowsHookEx(WH_CALLWNDPROC,
>(HOOKPROC)CDrawWnd::MyCallWndProc, NULL, ProcInfo.dwThreadId)

A non-static class member function has an invisible "this" pointer
parameter. If you make the function a static class function you should
have more success - though you may as well use a global function
anyway.

Dave
----
Address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow up email copies.



Mon, 01 Jan 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Q: subclassing problem, with hook and windows messages

2. Windows hooking and MFC /was Re: trap Windows message

3. Journaling using Windows Message Hooks

4. Using hooks to block messages going to windows?

5. Problems with Message hooking

6. windows hook problem???

7. Windows Hook Problem

8. Windows Hooks problem

9. Problems with System wide hooks and Windows 95

10. Windows.Forms.Message - processing a user defined Windows-message - 2nd try

11. Windows Message Handling problem

12. Add Windows Message Handler problems

 

 
Powered by phpBB® Forum Software