Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++

C++Builder WinExec() and CreateProcess()

Author: Embarcadero USA

 Question and Answer Database

FAQ1378C.txt   C++Builder WinExec() and CreateProcess()
Category   :Windows API
Platform    :All
Product    :C++Builder  1.x

Question:

I am updating my code for Win32 and changing my WinExec() 
calls to CreateProcess() and having trouble. There is so 
much more to setup.  Can you supply an example?

Answer:

void CreateChildProcessAndWaitUntilDone(const AnsiString& strCmdLine) 
{
   
        PROCESS_INFORMATION     piProcInfo; 
        STARTUPINFO             siStartInfo;

        // Set up members of STARTUPINFO structure.
        siStartInfo.cb          = sizeof(STARTUPINFO); 
        siStartInfo.lpReserved  = NULL;
        siStartInfo.lpReserved2 = NULL; 
        siStartInfo.cbReserved2 = 0;
        siStartInfo.lpDesktop   = NULL; 
        siStartInfo.dwFlags     = 0;


        // Create the child process.
        CreateProcess(

            NULL,
            strCmdLine.c_str(),
            NULL,           // process security attributes
            NULL,           // primary thread security attributes
            0,              // handles are inherited
            0,              // creation flags
            NULL,           // use parent's environment
            NULL,           // use parent's current directory
            &siStartInfo,   // STARTUPINFO pointer
            &piProcInfo);   // receives PROCESS_INFORMATION

            // Wait for the processs to finish
            DWORD rc = WaitForSingleObject(
                          piProcInfo.hProcess, // process handle
                          INFINITE); 
    }

        

7/2/98 10:32:32 AM
 

Article originally contributed by Borland Staff

RAD Studio 13.2 Florence Now Available! Kai 1.1.1 Now Available! What's Coming in RAD Studio 13.2 Florence

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.

Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES