Learn how to a build a cloud-first strategyRegister Now


Command Line Parsing

Posted on 2004-11-09
Medium Priority
Last Modified: 2013-11-20
Hello all:

   I added a command line to my MFC SDI project and now it bails with an error.  I traced the problem to the following:

      // Parse command line for standard shell commands, DDE, file open
      CCommandLineInfo cmdInfo;

      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
            return FALSE;

  It appears that when I specify a command line ProcessShellCommand can't handle it.  It also seems that when this method succeeds my main frame is created.  When it fails the main frame isn't created and the application bails.  I'm not sure what I need to do to get around this.  Is it possible that what I think is a command line is actually something else?

Thank you,
Question by:Catalepsy
  • 2
  • 2
LVL 30

Expert Comment

ID: 12540707
Exactly in what function did you add this code to?
LVL 30

Expert Comment

ID: 12540721
The above code should be in your CWinApp::InitInstance member function.
LVL 45

Expert Comment

ID: 12541798
For your clarification

C:\somewhere\someapp.exe "hello world"

here there is a command line with the suppplied parameter "hello world"

What do you supply as a command line - the default behaviour checks for certain things.  Are you supplying a custom parameter that is being treated as something else?

Author Comment

ID: 12544579
I've added no command line code whatsoever.  The above pasted code is what is in the App.  What I've done is add the command line through the project settings.  What I found was that by adding garbage such as adlfjkasdlfjasdlfkjadf as the command line the program produces the following dialog box.  C:\Projects\Project Name\adlfjkasdlfjasdlfkjadf was not found.  This is produced in ProcessShellCommand(cmdInfo).  Basically, the flag states FileOpen if there is a command line and FileNew if there isn't one.  If I force cmdInfo.m_nShellCommand to CCommandLineInfo::FileNew the program runs.  I consider this to be a little hokey but it accomplishes what I ultimately wanted.  In any event this doesn't seem like the right way for this to work.  I don't want the program to assume I'm opening a file because this application will not.  What would be the correct way to accomplish this?

LVL 45

Accepted Solution

AndyAinscow earned 400 total points
ID: 12544659
The neatest way is to define your own behaviour
eg as command line -x"Do something with this"
Now your provide an overriden class for the commandline info, find your specific commands, process them then pass what is left onto the base class for the default handling

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question