Click here to Skip to main content
Click here to Skip to main content
Go to top

A Command Line Class

, 1 Oct 2001
Rate this:
Please Sign up or sign in to vote.
A class that permit to get easily the command line parameters
<!-- Download Links -->

Overview

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.


Sample

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Carlos Antollini
Architect Citigroup
Argentina Argentina
Carlos Antollini is a software engineer working on Object Oriented, Visual C++, MFC, COM, ATL, ADO, Internet technologies and Business Intelligence.
Carlos is originally from Argentina, he was living for several years in Fort Lauderdale, Florida, working for Citibank. Then he started his own business.
Carlos is the creator of piFive[^], a family of BI Analytic Platform software, that it deals next to, latinsys[^], his partner in businesses...
Currently he is sharing his passion for project management and BI at Citigroup.

Comments and Discussions

 
GeneralSpace between arguments PinmemberPresu27-Oct-08 19:09 
GeneralRe: Space between arguments PinmemberChewsHumans22-Sep-09 16:49 
Generalvery helpfull stuff !!! Pinmembersani chabi yo2-Jun-05 6:36 
Generalhelp!! Pinmembermonimicki13-Dec-04 13:35 
GeneralRe: help!! Pinmemberbebenuage23-Dec-04 2:56 
GeneralRe: help!! Pinmembermonimicki23-Dec-04 20:31 
GeneralRe: help!! PinmemberMikael_Segerstein1-Mar-05 7:41 
GeneralRe: help!! [modified] PinmemberGilC6-Aug-09 0:09 
GeneralDoes not work as intended PinmemberDavidCrow4-Dec-03 8:13 
GeneralRe: Does not work as intended PinmemberTerry O'Nolley29-Jun-04 13:25 
GeneralScroll Bar PinmemberHump227-Jan-03 20:47 
GeneralQuestion on CCommanLine class PinmemberAnonymous16-May-02 18:03 
GeneralRe: Question on CCommanLine class PinmemberCarlos Antollini16-May-02 18:07 
GeneralClass rewrite PinmemberB.Mayrargue8-Oct-01 0:03 
GeneralRe: Class rewrite PinmemberCarlos Antollini9-Oct-01 3:41 
GeneralRe: Class rewrite Pinmemberdazinith9-Oct-02 6:43 
GeneralSome fixes for your modification Pinmemberdazinith9-Oct-02 9:27 
GeneralRe: Some fixes for your modification PinmemberSquirrel Twirler26-Apr-05 6:50 
GeneralRe: Some fixes for your modification PinmemberDimok13-May-05 23:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 2 Oct 2001
Article Copyright 2001 by Carlos Antollini
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid