billcch
asked on
ShellExecute and waiting the execute file finish
I have the following code
HANDLE hShell;
hShell = ShellExecute(NULL, "open", "test.exe", "parameter1 parameter2", "C:\\", SW_SHOWDEFAULT);
CloseHandle(hShell);
MessageBox(NULL, "text.exe finished", "myProg", MB_OK);
But I would like the message "text.exe finished" display after test.exe has been finished.
Please help me....
HANDLE hShell;
hShell = ShellExecute(NULL, "open", "test.exe", "parameter1 parameter2", "C:\\", SW_SHOWDEFAULT);
CloseHandle(hShell);
MessageBox(NULL, "text.exe finished", "myProg", MB_OK);
But I would like the message "text.exe finished" display after test.exe has been finished.
Please help me....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Um, and a lil' correction - the call above should have read
ExecuteAndWaitForCompletio n ( "test.exe parameter1 parameter2");
ExecuteAndWaitForCompletio
ASKER
Thank you so much....
one small question...
I used to use std::string,
what different between std::string and LPSTR?
Thanks...
one small question...
I used to use std::string,
what different between std::string and LPSTR?
Thanks...
>>what different between std::string and LPSTR?
'LPSTR' is a plain 'C' style string. So, you could just use
std::string str("test");
LPSTR pstr = str.c_str();
'LPSTR' is a plain 'C' style string. So, you could just use
std::string str("test");
LPSTR pstr = str.c_str();
ASKER
thank you so much
DWORD ExecuteAndWaitForCompletio
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRes;
DWORD dwCode = 0;
MSG msg;
ZeroMemory ( &si, sizeof ( STARTUPINFO));
si.cb = sizeof ( STARTUPINFO);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
bRes = CreateProcess ( NULL,
pszCmd,
NULL,
NULL,
TRUE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&si,
&pi
);
while ( WAIT_OBJECT_0 != MsgWaitForMultipleObjects ( 1,
&pi.hProcess,
FALSE,
INFINITE,
QS_ALLINPUT
)
)
{
while ( PeekMessage ( &msg, NULL, 0, 0, PM_REMOVE))
{
DispatchMessage ( &msg);
}
}
GetExitCodeProcess ( pi.hProcess, &dwCode);
CloseHandle ( pi.hProcess);
CloseHandle ( pi.hThread);
return ( dwCode);
}
and call it like
ExecuteAndWaitForCompletio