Command Line Parsing

Posted on 2004-11-09
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
    LVL 30

    Expert Comment

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

    Expert Comment

    The above code should be in your CWinApp::InitInstance member function.
    LVL 43

    Expert Comment

    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?
    LVL 3

    Author Comment

    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 43

    Accepted Solution

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Title # Comments Views Activity
    ORA-01403: no data found 43 75
    how to monitor remote shell execution on linux 9 89
    centeredAverage challenge 8 89
    NotAlone Challenge 20 65
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    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.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now