Click here to Skip to main content
15,905,590 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Best way to check if a thread is still active c++ win32 Pin
Randor 21-Feb-12 14:27
professional Randor 21-Feb-12 14:27 
AnswerRe: Best way to check if a thread is still active c++ win32 Pin
jkirkerx21-Feb-12 15:18
professionaljkirkerx21-Feb-12 15:18 
GeneralRe: Best way to check if a thread is still active c++ win32 Pin
Randor 21-Feb-12 16:55
professional Randor 21-Feb-12 16:55 
GeneralRe: Best way to check if a thread is still active c++ win32 Pin
jkirkerx21-Feb-12 17:05
professionaljkirkerx21-Feb-12 17:05 
AnswerRe: Best way to check if a thread is still active c++ win32 Pin
Chuck O'Toole21-Feb-12 14:29
Chuck O'Toole21-Feb-12 14:29 
GeneralRe: Best way to check if a thread is still active c++ win32 Pin
jkirkerx21-Feb-12 15:28
professionaljkirkerx21-Feb-12 15:28 
AnswerRe: Best way to check if a thread is still active c++ win32 Pin
Chuck O'Toole21-Feb-12 16:12
Chuck O'Toole21-Feb-12 16:12 
AnswerComplete code for CreateProcess and loop Pin
jkirkerx21-Feb-12 15:26
professionaljkirkerx21-Feb-12 15:26 
This is the complete code I wrote.

If no one has an objection to the GetExitCodeProcess in the loop, I'll stick with it because it works. I just thought it was completely wrong to use, or perhaps I'm just getting better at this.

C#
if (CreateProcess(sz_SQLServer_Install_FileName, szParameters, NULL, NULL, FALSE, CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS, 0, sz_SQLServer_Install_FolderPath, &si, &pi) ) {
        while(WAIT_TIMEOUT == WaitForSingleObject(pi.hProcess, 10)) {
            MSG oMSG;
            while(::PeekMessage(&oMSG, NULL, 0,0, PM_NOREMOVE)) {
                if(::GetMessage(&oMSG, NULL, 0,0) ) {
                    ::TranslateMessage(&oMSG);
                    ::DispatchMessage(&oMSG);
                }
                else {
                    break;
                }

                // Run the Cosmetics on the MDI Window
                if (ndx != 100) {
                    SendMessage(g_SQLServer_Install_Progress_Bar, PBM_SETPOS, (WPARAM)ndx, 0);
                    UpdateWindow(g_SQLServer_Install_MDIWindow);
                    Sleep(100);
                    ++ndx;

                }
                else {
                    if( iMO == 0 ) {
                        SetWindowText(g_SQLServer_Install_Progress_Text, L"Installation may take up to 30 minutes");
                        iMO = 1;
                    }
                    else {
                        SetWindowText(g_SQLServer_Install_Progress_Text, L"Installing Microsoft SQL Server Express 2008");
                        iMO = 0;
                    }

                    UpdateWindow(g_SQLServer_Install_MDIWindow);
                    ndx = 0;
                }

                // Check the process to see if it's still running
                GetExitCodeProcess(pi.hProcess, (unsigned long *)&exit_status);
                if (exit_status != 259)
                    break;
            }
        }

        GetExitCodeProcess(pi.hProcess, (unsigned long *)&exit_status);
        if (exit_status == 0) {
            // The program completed successfully
            SendMessage(g_SQLServer_Install_MDIWindow, WM_COMMAND, (WPARAM)g_SQLServer_Install_IDC_COMMAND, (LPARAM)g_SQLServer_Install_IDM_COMPLETE );
        }
        else {
            // The program was either canceled or failed for some reason
            SendMessage(g_SQLServer_Install_MDIWindow, WM_COMMAND, (WPARAM)g_SQLServer_Install_IDC_COMMAND, (LPARAM)g_SQLServer_Install_IDM_CANCEL );
        }

        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        exitCode = 1;
        bResult = TRUE;

AnswerRe: Complete code for CreateProcess and loop Pin
Chuck O'Toole21-Feb-12 16:22
Chuck O'Toole21-Feb-12 16:22 
AnswerRe: Complete code for CreateProcess and loop Pin
Chuck O'Toole21-Feb-12 16:34
Chuck O'Toole21-Feb-12 16:34 
GeneralRe: Complete code for CreateProcess and loop Pin
jkirkerx21-Feb-12 16:50
professionaljkirkerx21-Feb-12 16:50 
GeneralRe: Complete code for CreateProcess and loop Pin
Randor 21-Feb-12 17:08
professional Randor 21-Feb-12 17:08 
GeneralRe: Complete code for CreateProcess and loop Pin
jkirkerx21-Feb-12 18:18
professionaljkirkerx21-Feb-12 18:18 
GeneralRe: Complete code for CreateProcess and loop Pin
jkirkerx22-Feb-12 6:58
professionaljkirkerx22-Feb-12 6:58 
QuestionDynamic linking vs dynamic loading Pin
elelont221-Feb-12 4:47
elelont221-Feb-12 4:47 
QuestionRe: Dynamic linking vs dynamic loading Pin
David Crow21-Feb-12 5:41
David Crow21-Feb-12 5:41 
AnswerRe: Dynamic linking vs dynamic loading PinPopular
Chris Losinger21-Feb-12 5:47
professionalChris Losinger21-Feb-12 5:47 
QuestionHow to increase concurrent rate of a server application Pin
yu-jian21-Feb-12 3:30
yu-jian21-Feb-12 3:30 
AnswerRe: How to increase concurrent rate of a server application Pin
Richard MacCutchan21-Feb-12 5:20
mveRichard MacCutchan21-Feb-12 5:20 
AnswerRe: How to increase concurrent rate of a server application Pin
Randor 21-Feb-12 8:32
professional Randor 21-Feb-12 8:32 
QuestionWin7 - worker thread freeze on call to WaitForSingleObject Pin
Stan the man21-Feb-12 0:12
Stan the man21-Feb-12 0:12 
AnswerRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
Jochen Arndt21-Feb-12 0:29
professionalJochen Arndt21-Feb-12 0:29 
GeneralRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
Stan the man21-Feb-12 1:31
Stan the man21-Feb-12 1:31 
AnswerRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
bjorn_ht21-Feb-12 1:16
bjorn_ht21-Feb-12 1:16 
AnswerRe: Win7 - worker thread freeze on call to WaitForSingleObject Pin
Erudite_Eric21-Feb-12 2:31
Erudite_Eric21-Feb-12 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.