[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

CreateProcessEX, a function that extends CreateProcess, doesn't work under very specific conditions.

Asked by sternocera in Windows MFC Programming, C++ Programming Language

Tags: createprocessex, createprocess

CreateProcessEx is a function that extends CreateProcessEx a little - it minimizes the main app window while the external process is run, and then maxamises it again when it finishes.

This works nicely in almost all circumstances. If I call notepad like this:

CreateProcessEx("NOTEPAD.EXE",NULL /*arguments*/, TRUE, FALSE, TRUE, TRUE, NULL);

Or like this:

CreateProcessEx("C:\\windows\\NOTEPAD.EXE",NULL /*arguments*/, TRUE, FALSE, TRUE, TRUE, NULL);

everything works as it should; my main window minimises, and then maxamises again when I close notepad.exe .

It just won't work for the program I actually want to call, which is pg_dump.exe, a command line utility through which SQL dumps are performed.

CreateProcessEx("C:\\test\\pg_dump.exe",NULL /*arguments*/, TRUE, FALSE, TRUE, TRUE, NULL);

If I open it in windows, I get a dos box flashing for a moment, because it needs command line arguments (I have some command line arguments for it, but thats not relevant to the problem at hand.)

My window won't minimise, and I see no flashing dos box. I tried intentionally corrupting the file with a hex editor, and now when I open it in windows explorer I get an error messagebox. However, when I attempt to open it using CreateProcessEx, I see no such message box. I've even tried renaming notepad.exe to pg_dump.exe, and it will open notepad (pg_dump.exe) then fine.

What have I failed to take into account? What error have I made?

This is the CreateProcessEx function in it's entirety:

 DWORD CreateProcessEx ( LPCSTR lpAppPath, LPCSTR lpCmdLine,
    BOOL bAppInCmdLine, BOOL bCompletePath,
    BOOL bWaitForProcess, BOOL bMinimizeOnWait, HWND hMainWnd ) {

    STARTUPINFO startupInfo;
    PROCESS_INFORMATION    processInformation;    

    char szAppPath    [ _MAX_PATH  ];
    char szCmdLine    [ _MAX_PATH  ];
    char drive        [ _MAX_DRIVE ];
    char dir        [ _MAX_DIR   ];
    char name       [ _MAX_FNAME ];
    char ext        [ _MAX_EXT ];

    szAppPath[ 0 ] = '\0';
    szCmdLine[ 0 ] = '\0';
   
    ZeroMemory( &startupInfo, sizeof( STARTUPINFO ));

    startupInfo.cb = sizeof( STARTUPINFO );

    ZeroMemory( &processInformation, sizeof( PROCESS_INFORMATION ));

    if ( bCompletePath ) {

        GetModuleFileName( GetModuleHandle( NULL ), szAppPath, _MAX_PATH );

        _splitpath( szAppPath, drive, dir, NULL, NULL );
        _splitpath( lpAppPath, NULL, NULL, name, ext );

        _makepath ( szAppPath, drive, dir, name, strlen( ext ) ? ext : ".exe" );
    }
    else strcpy( szAppPath, lpAppPath );

    if ( bAppInCmdLine ) {

        strcpy( szCmdLine, "\"" );
        strcat( szCmdLine, szAppPath );
        strcat( szCmdLine, "\"" );
    }

    if ( lpCmdLine ) {

        // We must use quotation marks around the command line (if any)...

        if ( bAppInCmdLine ) strcat( szCmdLine, " \"" );
                        else strcpy( szCmdLine, "\"" );

        strcat( szCmdLine, lpCmdLine );
        strcat( szCmdLine, "\"" );
    }

    DWORD dwExitCode = -1;
           
    if ( CreateProcess(    bAppInCmdLine ? NULL: szAppPath,    // lpszImageName
                        szCmdLine,                            // lpszCommandLine
                        0,                                    // lpsaProcess
                        0,                                    // lpsaThread
                        FALSE,                                // fInheritHandles
                        DETACHED_PROCESS,                    // fdwCreate
                        0,                                    // lpvEnvironment
                        0,                                    // lpszCurDir
                        &startupInfo,                        // lpsiStartupInfo
                        &processInformation                    // lppiProcInfo
                    )) {

        if ( bWaitForProcess ) {

            if ( bMinimizeOnWait )
                   
                if ( IsWindow( hMainWnd )) ShowWindow( hMainWnd, SW_MINIMIZE );
                #ifdef __AFX_H__
                else AfxGetMainWnd()->ShowWindow( SW_MINIMIZE );
                #endif

            WaitForSingleObject( processInformation.hProcess, INFINITE );

            if ( bMinimizeOnWait )

                if ( IsWindow( hMainWnd )) ShowWindow( hMainWnd, SW_RESTORE );
                #ifdef __AFX_H__
                else AfxGetMainWnd()->ShowWindow( SW_RESTORE );
                #endif

            GetExitCodeProcess( processInformation.hProcess, &dwExitCode );
        }
        else {

            CloseHandle( processInformation.hThread );
            CloseHandle( processInformation.hProcess );

            dwExitCode = 0;
        }
    }

    return dwExitCode;
}

Thanks in advance,
Sternocera
[+][-]08/28/07 06:38 AM, ID: 19782817Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Windows MFC Programming, C++ Programming Language
Tags: createprocessex, createprocess
Sign Up Now!
Solution Provided By: AndyAinscow
Participating Experts: 4
Solution Grade: A
 
[+][-]08/24/07 05:40 AM, ID: 19761539Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 05:41 AM, ID: 19761548Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/24/07 05:41 AM, ID: 19761550Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 05:42 AM, ID: 19761555Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 05:43 AM, ID: 19761568Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 05:47 AM, ID: 19761596Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 05:55 AM, ID: 19761650Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/24/07 05:59 AM, ID: 19761683Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 06:01 AM, ID: 19761697Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/24/07 07:39 AM, ID: 19762536Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/27/07 02:40 AM, ID: 19774409Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/27/07 02:50 AM, ID: 19774434Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/27/07 02:56 AM, ID: 19774452Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/07 05:23 AM, ID: 19782200Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 06:10 AM, ID: 19782568Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08/28/07 06:12 AM, ID: 19782586Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/07 06:12 AM, ID: 19782591Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 06:13 AM, ID: 19782599Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/07 10:31 AM, ID: 19785107Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/07 02:45 PM, ID: 19787205Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628