Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

WaitForSingleObject()

  • 04-03-2007 07:14PM
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    Hola,

    Can anyone tell me if RegisterWaitForSingleObject() is the callback equivalent of WaitForSingleObject().

    Basically I need to be able to get on with my program while checking the status of a handle created by CreateProcess() so that when the process closes I can do certain things.
    HANDLE *test = NULL;
    RegisterWaitForSingleObject(test,cmdhandle, cmd.DestroyCmd(),	0, INFINITE, WT_EXECUTEONLYONCE);
    

    And the callback function:
    WAITORTIMERCALLBACK CALLBACK rcmd::DestroyCmd()
    {
    	closesocket(conn);
    	return 0;
    }
    

    That's my best guess about what to do so far. It crashes, something about the "0" in the RegisterWaitForSingleObject call I think?


Comments

  • Registered Users, Registered Users 2 Posts: 2,157 ✭✭✭dazberry


    That seems pretty nifty alright. Using your sample I've managed to get a version working in Delphi (RegisterWaitForSingleObject isn't included for some reason so I had to include it manually).

    Anyway my C/C++ is really rusty... but my guess is that here...
    HANDLE *test = NULL;

    To me this would appear to be creating a pointer to a handle and initalising the pointer to null. Instead you need to be passing a non null pointer to the handle (even if the actual HANDLE "value" is undefined or INVALID_HANDLE_VALUE) if that makes sense?

    D.


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    You have to stick "#define _WIN32_WINNT 0x0500" at the top of your header file (or Delphi equivalent) for it to work because RegisterWaitForSingleObject() is XP only afaik.

    I didn't cop the HANDLE *test thing at all for whatever reason. Thanks, I'll try some more and get back to you.

    Otherwise I'll have to learn to use threads :/


  • Closed Accounts Posts: 1,567 ✭✭✭Martyr


    according to msdn, the prototype for the callback is

    [PHP]VOID CALLBACK WaitOrTimerCallback(
    PVOID lpParameter,
    BOOLEAN TimerOrWaitFired
    );[/PHP]

    does not return anything, and passes 2 arguements, which should be removed from the stack before returning to callee, your prototype does not accept any arguements???

    just a guess for why it crashes..


Advertisement