[c/c++ 11 - win32] - how using hooks?

using the SetWindowsHookEx(), i can create a hook procedure:
(every code is on a class)
1
2
static HHOOK hkb;
hkb=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)CallKeyboardProc,GetModuleHandle(NULL),0);

and the hook procedure:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 static LRESULT WINAPI CallKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
        {
            if (((DWORD)(lParam & 0x40000000)==0) &&(nCode==HC_ACTION))
            {
                //KeyboardDown
                PostMessage((HWND)lParam,SYSKEYDOW,wParam,lParam);

            }
            else if (((DWORD)(lParam & 0x40000000)==1) &&(nCode==HC_ACTION))
            {
                //KeyboardUp
                PostMessage(FindWindow(GetClassLong() NULL) ,SYSKEYDOW,wParam,lParam);

            }
            LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );
            return  RetVal;
        }

i need ask: can i send the 'this' with SetWindowsHookEx()?
because i need call some lambdas.
... can i send the 'this' with SetWindowsHookEx()?

No, the keyword 'this' is a way of referring to the object whos member function you are currently working inside of by pointer. It will not be a valid pointer to an object within the address space of another application. At the same time, I'm having a bit of trouble figuring out where Lambda's come into the equation. Let's start your question over from the beginning.

What is 'this' supposed to be within the context of you current question?
What are these Lambda's trying to do, and why did you choose this route over traditional functions?
1st i have 2 errors on code:

hkb=SetWindowsHookEx(WH_KEYBOARD_LL,(HOOKPROC)CallKeyboardProc,(HINSTANCE)GetModuleHandle(NULL),NULL);
now the function is realy called and i can detect the key messages:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
static HHOOK hkb;

        static LRESULT WINAPI CallKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
        {
            //MessageBox(NULL,"error", "Erro",MB_OK);
            if (((DWORD)(wParam == WM_KEYDOWN)) &&(nCode==HC_ACTION))
            {
                //KeyboardDown

                   MessageBox(NULL,"error", "down",MB_OK);

            }
            else if (((DWORD)(wParam == WM_KEYUP)) &&(nCode==HC_ACTION))
            {
                //KeyboardUp
                //MessageBox(NULL,"error", "up",MB_OK);


            }
            LRESULT RetVal = CallNextHookEx( hkb, nCode, wParam, lParam );
            return  RetVal;
        }

but i need ask: now i must send a message to the window, but i don't have direct access to the WND window :(
so how can i send the message to the window?
Topic archived. No new replies allowed.