Click to See Complete Forum and Search --> : How to terminate a process?


Tiffany Chen
March 31st, 1999, 02:52 AM
How do I terminate a process which was created by CreateProcess function?

Here is what I got so far:

void CMFPView::OnFaxEditor()

{

STARTUPINFO sinfo = {sizeof(sinfo), NULL, NULL, NULL, NULL, NULL, NULL,

NULL, NULL, NULL, NULL, STARTF_USESHOWWINDOW, SW_SHOW, 0, NULL,

NULL, NULL, NULL};

PROCESS_INFORMATION pinfo;

CreateProcess(NULL, "d:\\mfp\\faxNumStg-VB\\faxNumStg.exe",

NULL,NULL,FALSE,CREATE_DEFAULT_ERROR_MODE,NULL,NULL,

&sinfo,&pinfo);

}

The faxNumStg AP doesn't terminate unless user choose to close the AP. If user did not close faxNumStg AP, how do I

terminate faxNumStg AP automatically when the calling AP was terminated. Any suggestion would be greatly appreciated.

Thanks in advance.


Best Regards,

Tiffany Chen

Dazza
March 31st, 1999, 03:45 AM
You could use


TerminateProcess(pinfo.hProcess,nExitCode);


(and remember to close the handles pinfo.hProcess and pinfo.hThread).


This may be a bit abrupt though! Another alternative is to use FindWindow to get the main window to the FaxEditor and try sending a WM_CLOSE or WM_QUIT message to it. If this works, it will give the program a chance to shutdown a bit more gracefully.