Discussion Locked

CreateProcess Function

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

//I have the CreateProcess function working but how do i get the handle to exit the process when the program is completed?

//program follows

#include "stdafx.h"
#undef NULL
#define NULL 0

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
BOOL ret_bl;
STARTUPINFO sui;
PROCESS_INFORMATION pi;
sui.cb=sizeof(STARTUPINFO);
sui.wShowWindow=SW_SHOW;
ret_bl=CreateProcess(
NULL, // name of executable module
"Notepad.exe", // command line string
NULL, // SD
NULL, // SD
NULL, // handle inheritance option
REALTIME_PRIORITY_CLASS, //creation flags
NULL, // new environment block
NULL, // current directory name
&sui, // startup information
&pi // process information
);

// BOOL GetExitCodeProcess(
// HANDLE hprocess, //handle to the process
// LPDWORD lpExitCode //termination status

// void ExitProcess(
// UINT uExitCode // exit code for all threads
// );

return 0;
}

3 replies

by bill_h

The handle to the created process is comtained in the PROCESS_INFORMATION structure - returned in your call as &pi.

The PROCESS_INFORMATION structure is defined as follows:

typedef struct _PROCESS_INFORMATION {
HANDLE hProcess;
HANDLE hThread;
DWORD dwProcessId;
DWORD dwThreadId;
} PROCESS_INFORMATION;

Hope this helps...

This discussion is closed to new replies.