Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem w/ CreateProcess WaitForSingleObject

Status
Not open for further replies.

scecilia

Programmer
Jul 8, 2002
35
US
Hello,

I have a GUI with two buttons. Button "Execute" calls the following piece of code (processHandle is a global HANDLE):

ExecCmd::Run()
{
STARTUPINFO start;
PROCESS_INFORMATION pinfo;
memset(&start, 0, sizeof(STARTUPINFO));
start.cb = sizeof(start);
DWORD returnValue;
long time = 100;

returnValue =
CreateProcess(NULL, "C:\\Butterfly\\Butterfly.exe",
0, 0, TRUE, IDLE_PRIORITY_CLASS, 0, 0, &start, &pinfo);

processHandle = &(pinfo.hProcess);

do{
returnValue = WaitForSingleObject(pinfo.hProcess, time);
if (returnValue < 0) break;
DoEvents();
} while (returnValue != 0);

GetExitCodeProcess(pinfo.hProcess, &returnValue);
CloseHandle(pinfo.hProcess);
}

Another GUI Button &quot;Abort&quot; calls a function which uses the global handle to terminate the process:
TerminateProcess(processHandle, 1);

The PROBLEM I am having is that
1)Seems like the process is eating resources and the OS becomes quite slughish!!! The .exe in CreateProcess is a simple one which causes no problem at all outside this function.
2) The TerminateProcess does not work at all!

What am I doing wrong??
 
>> processHandle = &(pinfo.hProcess);
>> TerminateProcess(processHandle, 1);

that does not look right to me.

try

processHandle = pinfo.hProcess;

hope that helps
-pete
 
Thanks Pete. It DID work :)

I restarted the computer and the sluggishness went away as well, I guess I was leaking memory like crazy.

 
Just a side note... i ran into problems cause 2 values mean it is done. here is the code I used

DWORD waitVal;
do
{
m_verificationText += _T(&quot;.&quot;);
UpdateData(FALSE);
waitVal = WaitForSingleObject(pThread->m_hThread,1000) ;
}while(waitVal != WAIT_FAILED && waitVal != WAIT_OBJECT_0);

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top