// Create a shell item array object that can be accessed using IObjectCollection // or IShellItemArray. IObjectCollection lets items be added or removed from the collection. // For code that needs to run on Vista use SHCreateShellItemArrayFromIDLists() HRESULT CreateShellItemArray(REFIID riid, void **ppv) { *ppv = NULL; IShellLibrary *pLibrary; HRESULT hr = CoCreateInstance(CLSID_ShellLibrary, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pLibrary)); if (SUCCEEDED(hr)) { hr = pLibrary->GetFolders(LFF_ALLITEMS, riid, ppv); pLibrary->Release(); } return hr; }
__inline HRESULT SHLoadLibraryFromKnownFolder(REFKNOWNFOLDERID aFolderId, DWORD aMode, REFIID riid, void **ppv) { *ppv = NULL; IShellLibrary *plib; HRESULT hr = CoCreateInstance(CLSID_ShellLibrary, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&plib)); if (SUCCEEDED(hr)) { hr = plib->LoadLibraryFromKnownFolder(aFolderId, aMode); if (SUCCEEDED(hr)) { hr = plib->QueryInterface(riid, ppv); } plib->Release(); } return hr; }