Kirants, now that makes sense! Thanks. I will work this out in my code and let you know how it works. Thanks again!
Printable View
Kirants, now that makes sense! Thanks. I will work this out in my code and let you know how it works. Thanks again!
Your claim that you read the items is not vindicated in your posts where you have instantiated objects of the wrong class in spite of having been given clear instructions.Quote:
Originally Posted by sanclan
You were clearly instructed to ask if something was not understood.Quote:
Originally Posted by Me
You had nothing to ask. Did you? ;)
Excuse me but we here help people who attempt at helping themselves first.Quote:
Originally Posted by sanclan
Anyways, if code is what helps you, implement this -
...Create an instance of this, and pass it to CWinApp::ParseCommandLineCode:class CYourCommandLineInfo : public CCommandLineInfo
{
public:
void ParseParam(
const TCHAR* pszParam,
BOOL bFlag,
BOOL bLast
)
{
// Implement this to handle your parameters
}
};
Your ParseParam will be called for command line parameters, and you can implement it to set flags of essence.
Now, you have code... On a platter. :cool:
EDIT: Ah, I see Kiran has...
Sadly, I am surprised how few projects I have worked on have used this approach when it seems to be the most object oriented way and fitting nicely with existing framework also..Quote:
Originally Posted by Siddhartha
I tried using the Visual C++ 6.0 wizard to add this class to my project. I used the Generic C++ class. When I do this, does the code for the deriving of the CCommandLineInfo go into the CCustomCommandLineInfo.h?
What am I doing wrong? I am trying to create a class that reads the command line argument and based on the argument, runs in either an Operator mode (basic dialog gui asking for information and executing off of that information), Engineering mode (all dialogs and menus are shown and useable), or Server mode (no guis or dialog boxes).
Here is my CCommandLineParse.h code:
I am getting errors such as:Code://--------------
#pragma once
#include "afxwin.h"
class CCommandLineParse : public CCommandLineInfo
{
// Constructor/Destructor
public:
CCommandLineParse(void);
~CCommandLineParse(void);
BOOL IsEngineering(){return m_bEngineering;};
BOOL IsOperator(){return m_bOperator;};
BOOL IsServer() { return m_bServer;};
private:
BOOL m_bEngineering;
BOOL m_bOperator;
BOOL m_bServer;
};
//-------------------
Here is my CCommandLineParse.cpp code:
//-------------------------------------
#include "stdafx.h"
#include ".\commandlineparse.h"
CCommandLineParse::CCommandLineParse()
{
CCommandLineParse()
{
m_bEngineering = m_bOperator = m_bServer = FALSE;
}
//jhs 02/16/06 - variables to indicate the param passed
BOOL m_bEngineering ;//for /e
BOOL m_bOperator; //for /o
BOOL m_bServer;//for /s
//jhs 02/16/06 - public methods for checking these
public:
BOOL IsEngineering(){return m_bEngineering;};
BOOL IsOperator(){return m_bOperator;};
BOOL IsServer() { return m_bServer;};
virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast)
{
if(0 == strcmp(pszParam,"/e"))
{
m_bEngineering = TRUE;
}
else if(0 == strcmp(pszParam,"/o"))
{
m_bOperator = TRUE;
}
else if(0 == strcmp(pszParam,"/s"))
{
m_bServer = TRUE;
}
}
}
CCommandLineParse::~CCommandLineParse(void)
{
}
//--------------------------------------------
Quote:
c:\Working\MapTextConverter\CommandLineParse.cpp(6): error C2143: syntax error : missing ';' before '{'
c:\Working\MapTextConverter\CommandLineParse.cpp(16): error C2143: syntax error : missing ';' before 'public'
c:\Working\MapTextConverter\CommandLineParse.cpp(17): error C2143: syntax error : missing ';' before '{'
c:\Working\MapTextConverter\CommandLineParse.cpp(17): error C2534: 'CCommandLineParse' : constructor cannot return a value
c:\Working\MapTextConverter\CommandLineParse.cpp(17): error C2562: 'CCommandLineParse::CCommandLineParse' : 'void' function returning a value
c:\Working\MapTextConverter\CommandLineParse.cpp(18): error C2601: 'IsOperator' : local function definitions are illegal
c:\Working\MapTextConverter\CommandLineParse.cpp(19): error C2601: 'IsServer' : local function definitions are illegal
c:\Working\MapTextConverter\CommandLineParse.cpp(22): error C2575: 'ParseParam' : only member functions and bases can be virtual
c:\Working\MapTextConverter\CommandLineParse.cpp(22): error C2601: 'ParseParam' : local function definitions are illegal
Why are you writing functions inside functions ?
Please bring them out..
- in your commandlineparse.h file class declaration, you do not have ParseParam..
- in the .cpp file, write all the functions in declared in .h file seperately qualified by CCommandLineParse:: ( this means they are all class members )
Code:CCommandLineInfo::CCommandLineInfo()
{
...contents here
}
BOOL CCommandLine::ParseParam(...)
{
...contents here
}
- Please make it a habit to look at the style of the appwizard generated code and follow similarly if you have confusion.
- When you hit a compiler error, make it a point to understand it. It doesn't harm in using the best available tools available to you ( MSDN ) before you post in codeguru. Place caret on the compiler errror, for e.g. C2601 and hit F1. This will bring up the help for that error.
Visual Studio IDE, MSDN etc. are your friends. Get to know them and you will have fun.- Please use code tags while posting code snippets. See my signature on how to use them.
Hi ...
Just a follow-up. I have implemented this code and it is working good with a couple small modifications. Below is the full implementatio into a CWinApp derived application. I will instanciate the class in the InitInstance() method and then parse the command line.
Thanks,
Chris
IMPEACH BUSH !
Code://///////////////////////////////////////////////////////////////////////////////////
// CustomCommandLineInfo.h : header file
/////////////////////////////////////////////////////////////////////////////////////
#if !defined(CUSTOM_COMMAND_LINE_INFO_)
#define CUSTOM_COMMAND_LINE_INFO_
class CCustomCommandLineInfo : public CCommandLineInfo
{
// Construction
public:
CCustomCommandLineInfo();
virtual void ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast);
//for convenience maintain 3 variables to indicate the param passed.
BOOL m_bExport ;//for /e
BOOL m_bOpen; //for /o
BOOL m_bWhatever;//for /whatever
//public methods for checking these.
public:
BOOL IsExport(){return m_bExport;};
BOOL IsOpen(){return m_bOpen;};
BOOL IsWhatever() { return m_bWhatever;};
};
#endif // !defined(CUSTOM_COMMAND_LINE_INFO_)
/////////////////////////////////////////////////////////////////////////////////////
// CustomCommandLineInfo.cpp Implementation
/////////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CustomCommandLineInfo.h"
CCustomCommandLineInfo::CCustomCommandLineInfo()
{
m_bExport = m_bOpen = m_bWhatever = FALSE;
}
void CCustomCommandLineInfo::ParseParam(const char* pszParam, BOOL bFlag, BOOL bLast)
{
if(0 == strcmp(pszParam,"o"))
{
m_bOpen = TRUE;
}
else if(0 == strcmp(pszParam,"e"))
{
m_bExport = TRUE;
}
else if(0 == strcmp(pszParam,"whatever"))
{
m_bWhatever = TRUE;
}
}
/////////////////////////////////////////////////////////////////////////////////////
// CTestMmcSnapInRunApp initialization
/////////////////////////////////////////////////////////////////////////////////////
#include "CustomCommandLineInfo.h"
BOOL CTestMmcSnapInRunApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CCustomCommandLineInfo oInfo;
ParseCommandLine(oInfo);
if(oInfo.IsExport())
{
Beep(1000, 100);
}
else if(oInfo.IsWhatever())
{
Beep(1000, 100);
}
else if(oInfo.IsOpen())
{
Beep(1000, 100);
}
else
{
// Call this method to load the mmc and exit this app.
LoadMmcApplication();
}
CTestMmcSnapInRunDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}