Thread: ShellExecute problem

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    8

    ShellExecute problem

    I have a part in my single dialog visual C++ program that does a shell execute.... ShellExecute(this->m_hWnd,"open", blah blah.

    The problem is I have another one after that, but in between those I have some code, BUT it executes the first program, doesnt wait untill the first program is terminated, and does the code and opens the second program while the first is still open! How do I get it to execute a program and stop executing code untill that program terminates?

  2. #2
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    Check the flags for ShellExecute, I am sure there is a way to do that. You can also use system() which does block until done.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    This is actually a windows programming problem, not C++ as such.

    ShellExecute() does not wait for the program executed to complete. If you want to do that, look up CreateProcess(). The usage of that function is more complex(you have more control, and can get more information about the new process being executed). The last argument contains a handle to a process. If you wait on that handle using WaitForSingleObject() or a similar function, you can wait until the spawned program exits.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM