Thread: where's my command line?

  1. #1

    Unhappy where's my command line?


    I'm writing a program in MS Visual C++, using the MFC AppWizzard. I want to be able to pass a command line option to my program when I run it. How can I get to find out what command line the application was passed?


    Phli Drew.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    The API function GetCommandLine() will return a pointer to the command line.

  3. #3
    Registered User
    Join Date
    Dec 2001
    If you have AppWizard generated application, look into your InitInstance () function, and you will see something like this

    CCommandLineInfo cmdInfo;
    ParseCommandLine (cmdInfo);
    if (!ProcessShellCommand (cmdInfo))
    return FALSE;

    >>> from MSDN help >>>

    1. After being created in InitInstance, the CCommandLineInfo object is passed to ParseCommandLine.

    2. ParseCommandLine then calls CCommandLineInfo::ParseParam repeatedly, once for each parameter.

    3. ParseParam fills the CCommandLineInfo object, which is then passed to ProcessShellCommand.

    4. ProcessShellCommand handles the command-line arguments and flags


    If you want to process your own flags, you must derive a new class from CCommandLineInfo and override its ParseParam () function. There are some options like /p etc. which must be handled.

    See CCommandLineInfo::ParseParam () in the help for more.

Popular pages Recent additions subscribe to a feed