MFC application crashing in ProcessShellCommand() when file to open specified on command line

前端 未结 3 475
隐瞒了意图╮
隐瞒了意图╮ 2021-01-19 18:03

The problem I need to solve is how to use the MFC function ProcessShellCommand() in the InitInstance() of a CWinApp to process a File

3条回答
  •  终归单人心
    2021-01-19 18:44

    I'm updating a desktop application from VC++ to Visual Studio 2017 and encountered the same problem when the user was trying to open a File with a double click from the Explorer. In my case, I just had to add this code:

    // Initialize OLE libraries
    if (!AfxOleInit())
    {
        AfxMessageBox("Could not open the file! \nTry open CS Setup first and then open the file using the menu \"File->Open...\".", MB_ICONERROR);
        return FALSE;
    }
    

提交回复
热议问题