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

Thread: How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

  1. #1
    Join Date
    Jul 2001
    Posts
    306

    Question How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

    Hello,

    from my main app I want to call another gui-app.
    But what is the correct way?
    Ok, first I need to call CreateProcess.
    But then?
    Do I need to follow it by Waitforsingleobject or MsgWaitForMultipleObjects?
    What could happen, if I do not use Waitforsingleobject/ MsgWaitForMultipleObjects?
    If I really need one of these wait-functions: what are the correct parameters?

    Thank you for any hints.

    br
    Ralf

  2. #2
    Join Date
    Aug 2006
    Posts
    232

    Re: How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

    You can call WaitForSingleObject unless you have a thread that creates windows.

    To wait until the other process has finished:

    Code:
    DWORD result = WaitForSingleObject( info.hProcess, INFINITE );
    ...where info is the same PROCESS_INFORMATION struct that was sent to CreateProcess.

    Waiting is optional, you don't need to call it. Then your application will keep running alongside the other process.
    Last edited by TubularX; July 22nd, 2016 at 03:06 AM.

  3. #3
    Join Date
    Jul 2001
    Posts
    306

    Re: How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

    the new thread creates windows!
    What is the difference to WaitForInputIdle instead of MsgWaitForMultipleObjects?

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,605

    Re: How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

    Quote Originally Posted by Ralf Schneider View Post
    from my main app I want to call another gui-app.
    But what is the correct way?
    Correct way for what? What your main app does expect from the "another gui-app"?

    It's absolutely unclear from your post what is the purpose of running gui-app. In case there is no communication expected between the two, your main app may just start the other app and forget about it. Of course there's no place for waiting of any kind in a scenario like that.

    Absolutely different thing is running gui app and pushing the one foreground, even with no communication expected. It will require your main app waiting for gui app entering idle input state, then attaching thread input and calling SetForegroundWindow.

    As you can see, the "correct way" may vary from "do nothing" to "do a very, very special thing".
    Best regards,
    Igor

  5. #5
    Join Date
    Jul 2001
    Posts
    306

    Re: How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

    Hello Igor,

    there is no special communication needed.
    But it will be good if the main app waits until the new app shows its window.
    What is needed for that?

    thx.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,605

    Re: How to call CreateProcess and Waitforsingleobject/ MsgWaitForMultipleObjects?

    What your main app is going to do until the new app shows itself? Show some fancy animation? Block user input? Freeze? If none of those, you'd better do no waiting at all.

    What does "it will be good main app waits" really mean? Say it waits and finds the new app hangs or crashes or just not shows up. Does it matter for main app to know that exact thing that happened? Is it able to handle the situation proper way? In case it is not, you'd better do no waiting at all.
    Last edited by Igor Vartanov; July 26th, 2016 at 04:03 AM.
    Best regards,
    Igor

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)