windows - Incorrect folder locations returned from SHGetPathFromIDList -
i trying restrict users access location (windows, program files, etc.) , doing implementing ifolderfilter interface.
everything seems going fine until shouldshow function gets called , seems fall apart. initial folder pass in of c:\programdata\company\app\year , see that, file dialog shows hanging off desktop why when inspect folders contained in pidl c:\users\graham.reeds\desktop\windows, c:\users\graham.reeds\desktop\program files, etc. seemingly preventing them being matched csidl_ variables want prevent user selecting.
i tried using shgetpathfromidlistex
, shgetknownfolderidlist
vs2010 gives me 'identifier x undefined' including shlobj , link shell32.lib.
hresult stdmethodcalltype shouldshow(ishellfolder* sf, lpcitemidlist pidlfolder, lpcitemidlist pidlitem) { hresult resultcode = s_ok; ulong attributes = 0ul; if (succeeded(sf->getattributesof(1, &pidlitem, &attributes))) { char szpath[_max_path]; bool f = shgetpathfromidlist(pidlitem, szpath); // bool f = shgetpathfromidlistex(pidlitem, szpath, _max_path, 0); // folderid_windows / csidl_windows pidlist_absolute pidl; // if (succeeded(shgetknownfolderidlist(folderid_windows, 0, 0, &pidl))) if (succeeded(shgetfolderlocation(0, csidl_windows, 0, 0, &pidl))) { hresult hres = sf->compareids(0, pidlitem, pidl); if ((short)hresult_code(hres) == 0) { resultcode = s_false; } ilfree(pidl); } } return resultcode; }
what need able prevent folders appearing in browse folder. how can that?
shgetpathfromidlist
requires absolute pidl (one starting desktop @ top of namespace heirarchy , working down), passing pidlitem
single child pidl (pidlitem
relative pidlfolder
, not desktop).
instead of using shgetpathfromidlist
can use ishellfolder::getdisplaynameof
shgdn_forparsing
flag full path of item (e.g. sf->getdisplaynameof(pidlitem, ...)
).
the same problem happening compareids
call. ishellfolder::compareids
requires 2 pidls both relative specified folder, trying call 1 relative pidl , 1 absolute one.
one solution create absolute pidl out of pidlfolder
, pidlitem
using ilcombine
, pass compareids
, need use desktop folder comparison (you obtain shgetdesktopfolder
) rather using sf
.
Comments
Post a Comment