To start a process from within another process, call the CreateProcess function, which loads a new application into memory and creates a new process with at least one new thread.
The following code example shows the CreateProcess function prototype.
BOOL CreateProcess(LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory, LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation );
Because Windows CE does not support security or current directories and does not handle inheritance, the majority of the parameters must be set to NULL or 0. The following code example shows how the function prototype would look when all nonsupported features are taken into consideration.
BOOL CreateProcess(LPCTSTR lpApplicationName,
LPTSTR lpCommandLine, NULL, NULL, FALSE,
DWORD dwCreationFlags, NULL, NULL, NULL,
LPPROCESS_INFORMATION lpProcessInformation );
The first parameter, lpApplicationName, must contain a pointer to the name of the application to start. Windows CE does not support passing NULL for lpApplicationName and looks for the application in the following directories, in the following order:
The lpCommandLine parameter specifies the command line to pass to the new process. The command line must be passed as a Unicode string. The dwCreationFlags parameter specifies the initial state of the process after loading. The following table describes all of the supported flags.
Flag |
Description |
0 | Creates a standard process. |
CREATE_SUSPENDED | Creates a process with a suspended primary thread. |
DEBUG_PROCESS | Creates a process to be debugged by the calling process. |
DEBUG_ONLY_THIS_PROCESS | Creates a process to be debugged by the calling process, but doesn't debug any child processes that are launched by the process being debugged. This flag must be used in conjunction with DEBUG_PROCESS. |
CREATE_NEW_CONSOLE | Creates a new console. |
The last parameter used by CreateProcess is lpProcessInformation. This parameter points to the PROCESS_INFORMATION structure, which contains data about the new process. The parameter can also be set to NULL.
If the process cannot run, CreateProcess returns FALSE. For more information about the failure, call the GetLastError function.