Creating a Process with CreateProcess

< BACK  NEXT >
[oR]

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 CreateProcess
 void 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.

Table 5.1. CreateProcess Creates a new process
CreateProcess
LPCWSTR pszImageName, Name of application to run.
LPCWSTR pszCmdLine Command line arguments for application.
LPSECURITY_ATTRIBUTES psaProcess Not supported, pass as NULL.
LPSECURITY_ATTRIBUTES psaThread Not supported, pass as NULL.
BOOL fInheritHandles Not supported, pass as FALSE.
DWORD fdwCreate Flags specifying how to launch the application. Only the following are commonly used in Windows CE:
CREATE_NEW_CONSOLE Create a new console (only supported on platforms supporting cmd.exe)
CREATE_SUSPENDED Create process, but do not start executing thread.
PVOID pvEnvironment Not supported, pass as NULL.
LPWSTR pszCurDir Not supported, pass as NULL.
LPSTARTUPINFO psiStartInfo Not supported, pass as NULL.
LPPROCESS_INFORMATIONpProcInfo Pointer to a PROCESS_INFORMATION structure.
HANDLE Return Value Kernel object handle, or zero on error.

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:

  • hProcess A kernel object handle for the new process

  • hThread A kernel object handle for the primary thread for the new process

  • dwProcessId The process's system-wide unique identifier

  • dwThreadId The thread's system-wide unique identifier

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.


< BACK  NEXT >


Windows CE 3. 0 Application Programming
Windows CE 3.0: Application Programming (Prentice Hall Series on Microsoft Technologies)
ISBN: 0130255920
EAN: 2147483647
Year: 2002
Pages: 181

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net