How to get the command line arguments in MFC applications?

前端 未结 4 1394
迷失自我
迷失自我 2021-01-07 17:59

I wish to have a small dialog based application which is passed command line parameters, so, using VC++6 I ran the application wizard and chose an MFC dialog application.

相关标签:
4条回答
  • 2021-01-07 18:14

    Yes, see CWinApp:ParseCommandLine. Also take a look at the CCommandLineInfo class.

    0 讨论(0)
  • 2021-01-07 18:22

    In MFC applications, the entry point function is 'initInstance()', like main() or wmain(). Use CWinApp::m_lpCmdLine in initInstance() to access the command line.

    0 讨论(0)
  • 2021-01-07 18:25

    To get the raw command line use the following code (will work on any Win32 / MFC application):

    TCHAR *pCommandLine = ::[GetCommandLine()][1];
    int nArgc = 0;
    LPWSTR *pArgv = ::CommandLineToArgvW(pCommandLine, &nArgc);
    

    nArgc should be 1 when no arguments given and larger than 1 when there are. Then, pArgv1 will be the first argument, and so on...

    0 讨论(0)
  • 2021-01-07 18:34

    Use GetCommandLine(), which returns the name of the file being executed, followed by the arguments.

    The application member m_lpCmdLine (used like yourApp.m_lpCmdLine) contains only the arguments.

    There is also CWinApp::ParseCommandLine() that you may find useful.

    Also try the ATL COM wizard to create a non-MFC dialog application (chose the .exe option, not .dll).

    0 讨论(0)
提交回复
热议问题