I created this class with the idea of to get easily the parameters of command line.
This was inspired by the people of asked severeal times in the Question Forum the following:
- How Can I get the Command Line Parameters?
For this I created the CCommandLine
class
The CCommandLine Class.
CCommandLine::CCommandLine
Constructs a CCommandLine object.
CCommandLine();
CCommandLine::GetFirstParameter
The GetFirstParameter returns the first flag and its parameter.
BOOL GetFirstParameter(CString& strFlag, CString& strParam);
Parameters
CString& strFlag
Pointer to a buffer in which to return the Flag.
CString& strParam
Pointer to a buffer in which to return the Parameter.
If the function has parameters to return, returns TRUE
.
Remarks
If the command line has a parameter without flag, the strFlag
variable will be empty.
See Sample
CCommandLine::GetNextParameter
The GetNextParameter returns the next flag and its parameter.
BOOL GetNextParameter(CString& strFlag, CString& strParam);
Parameters
CString& strFlag
Pointer to a buffer in which to return the Flag.
CString& strParam
Pointer to a buffer in which to return the Parameter.
If the function has parameters to return, returns TRUE
.
Remarks
If the command line has a parameter without flag, the strFlag
variable will be empty.
See Sample
CCommandLine::GetCommandLine
The GetCommandLine returns the command line string for the application that is running.
void GetCommandLine(CString& strCommand);
Parameters
CString& strCommand
Pointer to a buffer in which to return the Command Line.
CCommandLine::GetAppName
The GetAppName returns the application name for the application that is running.
void GetAppName(CString& strAppName);
Parameters
CString& strAppName
Pointer to a buffer in which to return the Application Name.
CCommandLine::GetAppPath
The GetAppPath returns the complete path from where the application was executed.
void GetAppPath(CString& strAppPath);
Parameters
CString& strAppPath
Pointer to a buffer in which to return the Application Path.
BOOL CTestApp::InitInstance()
{
CCommandLine pCmd;
CString strFlag = _T("");
CString strParam = _T("");
BOOL bRet = pCmd.GetFirstParameter(strFlag, strParam);
while(bRet)
{
DoSomethingWithTheParameter(strFlag, strParam);
bRet = pCmd.GetNextParameter(strFlag, strParam);
}
.....
.....
}
Carlos A. Antollini.