The function CreateProcess is the standard way of creating processes. The code in Listing 5.1 prompts the user for the filename of an application (for example, "pword.exe" for Pocket Word) and then calls CreateProcess to run the application. Listing 5.1 Creates a process with CreateProcessvoid Listing5_1() { TCHAR szApplication[MAX_PATH]; PROCESS_INFORMATION pi; if(!GetTextResponse(_T("Enter Application to Run:"), szApplication, MAX_PATH)) return; if(CreateProcess(szApplication, NULL, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi) == 0) cout _T("Cannot create process") endl; else { CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } The CreateProcess function (Table 5.1) takes ten parameters, of which only two are essential in Windows CE for creating a process.
It is possible to pass a NULL for pszImageName, in which case pszCmdLine should point at a string containing the application filename followed by the command line arguments. If the application file name is not fully qualified, Windows CE will search in the "\Windows" folder followed by the root "\" folder. Platform builders can add an additional OEM-dependent folder and a "\ceshell" directory to the search. The last argument to CreateProcess is a PROCESS_INFORMATION structure in which four pieces of information about the new process are returned:
Kernel object handles and identifiers are described in the next section. For now, note that the handles returned in the PROCESS_INFORMATION structure must be closed by calling CloseHandle.
|