Hooked Procedure Early Return In/External Trigger

This is a discussion on Hooked Procedure Early Return In/External Trigger within the Windows Programming forums, part of the Platform Specific Boards category; Hooked Procedure Early Return In/External Trigger Hello, I've hooked into an application succesfully using WH_CALLWNDPROCRET or WH_CALLWNDPROC both give the ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    10

    Hooked Procedure Early Return In/External Trigger

    Hooked Procedure Early Return In/External Trigger

    Hello,

    I've hooked into an application succesfully using WH_CALLWNDPROCRET or WH_CALLWNDPROC both give the same issue detailed below.

    In the hooked callback function I trigger my code by waiting for a spceific window message.

    Once the hooked callback function receives this message, my code is triggered and executes a right click on an "Edit" window where normally a menu (which is a new handle) is created.

    Here is the rub, the menu window is not created until my call back function returns its value.

    So my code, though it sends the proper right click message, cannot find the menu, because the menu hasn't been created yet, because the hooked callback function has not returned its value (because my code is still executing).

    However, if i execute the code from outside of a hook (say i trigger it myself from a command line), the menu appears and my code can find the menu and everything works as I expect.

    What would be a work around for this.

    For instance could I use the hook function to post a message to a program i create designed to handle messages from this hooked procedure.

    I really don't want to do that, as that would mean changing from a command line to a gui event based program.

    Or can I make a command line program event based?

    My first question is, however, dealing with the 'delayed' menu window creation.

    For instance, is there a way to instantly return my hooked call back procedure and then proceed with my code?

    Thanks,

  2. #2
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    in the hook, create a worker thread that waits a predetermined amoutn of time, then executes the click. Thwe hook can reutrn, and the thread will execute the click a moment later.

    Be sure to close the previous threads handle prior to opening a new thread, or you will leak handles.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    10
    Let me make sure I understand what you are saying.

    1) within the hook, when the activation message is sent create a new thread (call it worker thread).
    2) have the worker thread wait a moment before it begins execution. (where it is waiting for the hook procedure to return).
    3) every time i create a new worker thread, be sure to close the previous worker thread (if any)

    Is this correct?

    Thanks,

  4. #4
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    If I understand you correctly, you should be able to hook messages that are posted when the menu is created. When you finally hook one of those messages, you can be sure that the menu is there when you execute the right click.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    10
    Thanks to both of you [btw: both of your signatures are great]

    Fish Salesman: The new thread idea with delayed execution allowed the original hookprocedure to return, the menu to be created, and then my right clicks would work. Thanks.

    God: That would have been nice; however, the menu would never be created as long as I was still in the original thread. I could do what you are saying from a new thread to be sure that the menu was there. Thanks.

    I consider this forum::thread solved.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  2. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21