Click here to Skip to main content
11,496,146 members (162 online)
Click here to Skip to main content

A Command Line Class

, 1 Oct 2001 107K 1.6K 38
A class that permit to get easily the command line parameters
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
<!-- 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 Pin
Presu27-Oct-08 20:09
memberPresu27-Oct-08 20:09 
GeneralRe: Space between arguments Pin
ChewsHumans22-Sep-09 17:49
memberChewsHumans22-Sep-09 17:49 
Generalvery helpfull stuff !!! Pin
sani chabi yo2-Jun-05 7:36
membersani chabi yo2-Jun-05 7:36 
Generalhelp!! Pin
monimicki13-Dec-04 14:35
membermonimicki13-Dec-04 14:35 
GeneralRe: help!! Pin
bebenuage23-Dec-04 3:56
memberbebenuage23-Dec-04 3:56 
GeneralRe: help!! Pin
monimicki23-Dec-04 21:31
membermonimicki23-Dec-04 21:31 
GeneralRe: help!! Pin
Mikael_Segerstein1-Mar-05 8:41
memberMikael_Segerstein1-Mar-05 8:41 
GeneralRe: help!! [modified] Pin
GilC6-Aug-09 1:09
memberGilC6-Aug-09 1:09 
GeneralDoes not work as intended Pin
DavidCrow4-Dec-03 9:13
memberDavidCrow4-Dec-03 9:13 
GeneralRe: Does not work as intended Pin
Terry O'Nolley29-Jun-04 14:25
memberTerry O'Nolley29-Jun-04 14:25 
GeneralScroll Bar Pin
Hump227-Jan-03 21:47
memberHump227-Jan-03 21:47 
GeneralQuestion on CCommanLine class Pin
Anonymous16-May-02 19:03
memberAnonymous16-May-02 19:03 
GeneralRe: Question on CCommanLine class Pin
Carlos Antollini16-May-02 19:07
memberCarlos Antollini16-May-02 19:07 
GeneralClass rewrite Pin
B.Mayrargue8-Oct-01 1:03
memberB.Mayrargue8-Oct-01 1:03 
GeneralRe: Class rewrite Pin
Carlos Antollini9-Oct-01 4:41
memberCarlos Antollini9-Oct-01 4:41 
GeneralRe: Class rewrite Pin
dazinith9-Oct-02 7:43
memberdazinith9-Oct-02 7:43 
GeneralSome fixes for your modification Pin
dazinith9-Oct-02 10:27
memberdazinith9-Oct-02 10:27 
GeneralRe: Some fixes for your modification Pin
Squirrel Twirler26-Apr-05 7:50
memberSquirrel Twirler26-Apr-05 7:50 
GeneralRe: Some fixes for your modification Pin
Dimok14-May-05 0:24
memberDimok14-May-05 0: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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 2 Oct 2001
Article Copyright 2001 by Carlos Antollini
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid