IFileDialog / IShellItem :: GetDisplayName does not work with Windows 7 libraries

IFileDialog *pfd;
...
CoCreateInstance(CLSID_FileOpenDialog,NULL,
   CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&pfd));
...
IShellItem *psiResult;
pfd->GetResult(&psiResult);
...
wchar_t *filepath;
psiResult->GetDisplayName(SIGDN_FILESYSPATH,&filepath);
...

This works fine for regular files, but it crashes (E_INVALIDARG) when the file is downloaded through the Windows 7 library folder (the same file will work when accessed via the normal path). doc says that:

SIGDN_FILESYSPATH (Returns the file system path element, if any. Only elements that report SFGAO_FILESYSTEM have a file system path. When the element does not have a file system path, calling IShellItem :: GetDisplayName on this element will fail . In the user interface, this name suitable for displaying to the user in some cases, but note that this may not be for all elements.

SIGDN_NORMALDISPLAY SIGDN .

, , Windows 7?

1

:

IShellItem *psiResult;
pfd->GetFolder(& psiResult); 
LPWSTR folderpath = NULL; 
psiResult->GetDisplayName(SIGDN_FILESYSPATH, & folderpath); 

GetDisplayName() pfd- > GetResult (& psiResult);

2

, , CoInitializeEx. COINIT_MULTITHREADED, COINIT_APARTMENTTHREADED, .

+3
1

pfd->SetOptions(dwOptions | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);

. .

+1

Source: https://habr.com/ru/post/1796438/


All Articles