class CProcessMgr

Process Manager Class

Public Methods

CProcessMgr ()
constructor
DWORD Execute (const CString & strCmdLine, BOOL bWait = FALSE)
Start a command with parameters in a specified directory
DWORD Execute ( const CString & strCmd, const CString & strArgs, const CString & strDir = "", BOOL bWait = FALSE )
Start a command with parameters in a specified directory
BOOL GetLinkInfo (const CString & LinkName, CString & Path)
Retrieves the filename a shell-link points to
DWORD IsProgramRunning (DWORD PID)
Determine whether a program is currently running or not
DWORD IsProgramRunning (const CString & FileName)
Determine whether a program is currently running or not
BOOL ParseCommand ( const CString & CmdLine, CString & Directory, CString & Cmd, CString & Args )
Parse a command string
BOOL SwitchProcessIntoForeground (DWORD dwPID)
Switch the process with the given PID into the foreground
BOOL SwitchProcessIntoForeground ( const CString & FileName )
Switch the process with the given PID into the foreground
DWORD Wait (DWORD PID)
Wait for the end of the process with process-ID <PID>
virtual ~CProcessMgr ()
destructor

Protected Methods

virtual void OnExecError ( int nErrorCode, const CString & strCommand )
Error handler

Private Methods

BOOL GetErrorText (int nError, CString & strErrText)
Retrieve a human readable messagetext for a system error number
LEXER LexCommand (CString & strToken)
Helper-function for the ParseCommand() method

Documentation

Process Manager Class. The class makes it easy to start and switch processes in a Win32 environment. One of the main goals of this class is its ability to handle complex command strings. A command string has the following syntax (BNF-like):
		CmdLine :	command
				|	command arguments
				|	'cd' directory ';' command
				|	'cd' directory ';' command arguments

		command	:	string

		arguments:	string
				|	arguments string

		directory:	string	// shall consist of a full path !

		string	:	'[^ \t]+'			//	string without blanks/tabs
				|	'"' '[^"]*' '"'		//	quoted string can
										//	contain any character
										//	except " itself

For those programmers who are not familiar with BNF-notation here are some samples for valid command strings:
		cmd
		cmd /c dir
		cd C:\windows ; cmd /c dir
		cd "C:\Program Files\Informix" ; cmd /c dir
		cd "C:\Program Files\Pictures" ; "\\picard\Software\Graphic Utilities\PSP\psp.exe" Title.jpg
Note that you have to double all occurencies of '\' in C/C++ source code!
CProcessMgr()
constructor

virtual ~CProcessMgr()
destructor

BOOL ParseCommand( const CString & CmdLine, CString & Directory, CString & Cmd, CString & Args )
Parse a command string. Extract the directory where the process should run, the command itself and its arguments. Note that <Cmd> can refer to any file (not just executables!). See "Execute()" below.

ParseCommand() returns TRUE, if <CmdLine> is syntactical correct and FALSE if not. It does not check whether <directory> or <command> are valid!

DWORD Execute( const CString & strCmd, const CString & strArgs, const CString & strDir = "", BOOL bWait = FALSE )
Start a command with parameters in a specified directory. You can set the parameter <bWait> to TRUE, if you want to wait for the end of the spawned process, before "Execute()" returns. If the <strCmd> does not refer to an executable file, then "Execute()" searches for an associated command for this type of file. The result of this function is either a PID (bWait==FALSE) or the exit-code of the process (bWait==TRUE) or DWORD(-1) if the command could not be spawned.

DWORD Execute(const CString & strCmdLine, BOOL bWait = FALSE)
Start a command with parameters in a specified directory. This overridden method parses the command string, before it executes the command.

DWORD Wait(DWORD PID)
Wait for the end of the process with process-ID <PID>. The result is the exit-code of that process or DWORD(-1) if the method failed to wait for such a process (possibly PID is invalid).
Parameters:
dwPID - process identifier

DWORD IsProgramRunning(const CString & FileName)
Determine whether a program is currently running or not. If <FileName> refers to a shell-link, then the link will be resolved and the filename the link points to will be used. Returns the process id (PID) of the program or 0 (null) if the program is currently not running.
Parameters:
FileName - name of an executable file

DWORD IsProgramRunning(DWORD PID)
Determine whether a program is currently running or not. This overridden method takes a process id instead of a filename to determine whether a certain process is running or not. Note that this method might not return what you expect, because in Win32 PIDs will be reused by the system, so it might happen that there is already a new process with this PID!
Parameters:
dwPID - process identifier

BOOL SwitchProcessIntoForeground(DWORD dwPID)
Switch the process with the given PID into the foreground. Returns TRUE on success and FALSE on failure (no such process or process has hidden windows only (possibly a DDE/OLE server) or the process does not have a window to activate) If the top-level window of this process is minimized, then it will be restored.
Parameters:
dwPID - process identifier

BOOL SwitchProcessIntoForeground( const CString & FileName )
Switch the process with the given PID into the foreground. This overridden method first determines whether the given Filename is a currently running process. If so, it uses its PID to switch that process into the foreground.
Parameters:
FileName - name of an executable file

BOOL GetLinkInfo(const CString & LinkName, CString & Path)
Retrieves the filename a shell-link points to. GetLinkInfo() returns TRUE on success and FALSE on failure (<Path> stays undefined on failure !)
Parameters:
LinkName - the filename of the shell link
Path - buffer for the path, the link points to

virtual void OnExecError( int nErrorCode, const CString & strCommand )
Error handler. The "OnExecError()" handler will be called if "Execute()" fails. The default implementation pops up a messagebox containing a human readable reason (english).
Parameters:
nErrorCode - system error number
strCommand - the command that caused the error

LEXER LexCommand(CString & strToken)
Helper-function for the ParseCommand() method. Extract the next token from a given command-String.
Parameters:
strToken - buffer for the next lexical token

BOOL GetErrorText(int nError, CString & strErrText)
Retrieve a human readable messagetext for a system error number. You can use GetErrorText(GetLastError(), str); for instance. The function returens TRUE on success and FALSE if it could not find an apropriate piece of text.
Parameters:
nError - system error number (use GetLastError() for instance)
strErrText - buffer for the descriptive text


This class has no child classes.

alphabetic index hierarchy of classes


generated by doc++