CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: "hook" problem

  1. #1
    Join Date
    Mar 2003
    Location
    Poland
    Posts
    73

    Question "hook" problem

    I would like to hook some app from another app. Hook procedure (keyboard type) is in exe file. I don't want to use global hook so I used "local" like this:

    HWND hwnd = ::FindWindow(NULL,"Some app to hook");
    if(hwnd == NULL) return;
    LPDWORD processID = NULL;
    UINT threadID = GetWindowThreadProcessId(hwnd,processID);
    if(threadID == 0) return;
    m_hHook = SetWindowsHookEx(WH_KEYBOARD,hookproc,NULL,threadID);

    When I use debug versions of both apps hook procedure is working correctly but when I use release versions it don't (SetWindowsHookEx is working fine). Any idea why?
    Maybe there is another way to take control of keyboard in some process. I tray also to use separate hooking dll, but when I used GetProcAddress to get pointers to exported funcions it always return NULL. Please help me.

  2. #2
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    If you want to hook an external application you must use a DLL. The reason is because an application can not access code outside of its address space, which includes code in your application. By putting the code into a DLL, the DLL can be loaded into the target process's address space.

    GetProcAddress may be failing because you are not using the "decorated name". There is a command line program that will tell you the name you need to use, or you can use depends i think.

  3. #3
    Join Date
    Mar 2003
    Location
    Poland
    Posts
    73
    Thanks! How to get the "real" names of dll functions?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured