mfc

CDocument::SetPathName(..) crash in VS2015


I upgrade an App from VS2008 to VS2015.

I get an Exception, which I assume is triggered from

/*virtual*/ BOOL CMyAppDoc::SaveModified()
{
  if (!IsModified())
    return TRUE;        // nothing to do

  CString str = GetPathName();
  SetPathName(str, TRUE);   // assign a PathName and add to MRU !
  return OnSaveDocument(str);           

}

The ErrorBox shows: "Encountered an inproper argument".


Solution

  • I investigated further, the error comes from

    void CRecentFileList::Add(LPCTSTR lpszPathName, LPCTSTR lpszAppID)
    {
      ..
      hr = _AfxSHCreateItemFromParsingName(lpWPath, NULL, IID_IShellItem,LPVOID*)&psi);
      ENSURE(SUCCEEDED(hr));
      ..
    
    }
    

    hr Errorcode is 2, which means ERROR_FILE_NOT_FOUND : The system cannot find the file specified.

    The workaround is first save the file with OnSaveDocument(..), then call SetPathName(..)