1
votes

I have a SDI application established in Visual Studio. I understood passing a file name to an application is fine like in the commandline: MyApp.exe "C:\a.txt". However it will not accept custom arguments or URLs. Say I cannot do MyApp.exe "SomethingILike" or MyApp.exe "www.google.com"

I understand the code to process arguments are in the ...App::InitInstance() There are

CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

if (!ProcessShellCommand(cmdInfo))
    return FALSE;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

Obviously the ProcessShellCommand rules out the arguments MFC does not think reasonable. How should I process my custom arguments? Say I want to pass "SomethingILike", now it tells me file-not-found and shuts off, but at least I want the application to start normally and I will have a chance to get

this->m_lpCmdLine

I cannot comment out the ProcessShellCommand if statement, otherwise it gives me an unhandled exception. Probably ProcessShellCommand does some initialization work too, which sounds not quite reasonable to me.

1

1 Answers

1
votes

You have to derive a class from CCommandLineInfo and override its virtual function ParseParam() to define your own processing of the parameters.

Here a demo on how to do it.