i have some problems with getting icons from other special folder than desktop..

may be anyone can help me ...
this sample try to retreive item icon
what is wrong? :-/
pls, explain ..

[--------------- c u t ------------------]

// console app
// msvc 6.0

#define WINVER 0x0500
#include <windows.h>
#include <shlobj.h>
#include <commctrl.h>
#include <stdio.h>


int main(void)
{
LPMALLOC lpmalloc;
LPSHELLFOLDER lpshellfolder;
LPSHELLFOLDER child;
LPENUMIDLIST lpenumidlist;
LPITEMIDLIST lpitemidlist;
LPITEMIDLIST childitemidlist;
SHFILEINFO shfileinfo;
STRRET strret;
char str[1024];
HIMAGELIST himagelist;

CoInitialize(0);
SHGetMalloc(&lpmalloc);

// get desktop folder
SHGetDesktopFolder(&lpshellfolder);

// get control panel folder
SHGetSpecialFolderLocation(NULL, CSIDL_CONTROLS, &childitemidlist);
lpshellfolder->lpVtbl->BindToObject(lpshellfolder, childitemidlist, NULL, &IID_IShellFolder, (LPVOID*)&child);

// get control panel item list
child->lpVtbl->EnumObjects(child, NULL, SHCONTF_NONFOLDERS, &lpenumidlist);
lpenumidlist->lpVtbl->Next(lpenumidlist, 1, &lpitemidlist, NULL);

// get icon list handle and icon index for requested item
himagelist = (HIMAGELIST)SHGetFileInfo((LPSTR)lpitemidlist, 0, &shfileinfo, sizeof(shfileinfo), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
wsprintf(str, "himagelist\t- 0x%x", himagelist);
printf("%s\n", str);
wsprintf(str, "iconindex\t- 0x%x", shfileinfo.iIcon);
printf("%s\n", str);

// unallocate used memory
lpmalloc->lpVtbl->Free(lpmalloc, lpitemidlist);
lpmalloc->lpVtbl->Free(lpmalloc, childitemidlist);

lpenumidlist->lpVtbl->Release(lpenumidlist);
child->lpVtbl->Release(child);
lpshellfolder->lpVtbl->Release(lpshellfolder);

lpmalloc->lpVtbl->Release(lpmalloc);
CoUninitialize();

return 1;
}

----
p.s. if you have another sample in c, asm, basic, pascal feel free to post in original language
Posted on 2003-08-05 20:34:06 by awlee