Command Line Parsing

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,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Exactly in what function did you add this code to?
The above code should be in your CWinApp::InitInstance member function.
AndyAinscowFreelance programmer / ConsultantCommented:
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?
CatalepsyAuthor Commented:
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?

AndyAinscowFreelance programmer / ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.