Why CFileDialog::GetNextPathName doesn't work when the file path is long?

前端 未结 2 967
广开言路
广开言路 2020-12-20 18:05

Using CFileDialog class, I select multiple files placed in a directory with a long path. It\'s OK when I select only one or two files; but when I select three f

2条回答
  •  半阙折子戏
    2020-12-20 19:02

    Assuming that your code looks something like this:

    CFileDialog dialog(...);
    dialog.DoModal();
    

    Determine the maximum number of files that you wish to support, for example:

    #define MAX_FILE_NAMES 256
    

    Add this before calling DoModal:

    CString data;
    dialog.m_pOFN->nMaxFile = (MAX_FILE_NAMES*(MAX_PATH+1))+1;
    dialog.m_pOFN->lpstrFile = data.GetBuffer((MAX_FILE_NAMES*(MAX_PATH+1))+1);
    

    Add this after calling DoModal:

    data.ReleaseBuffer();
    

提交回复
热议问题