I am using the following code ( for working out how to go about it ) to extract icons from files (exe / dll) and getting Access violation errors.
I have had success but the successes were random, by this I mean that if I opened the same file more than once it would work the first time then hang the second attempt to open with a TFileOpen dialog window.
On the second attempt, TFileOpen->Execute() did not produce a file open window.
I have searched and searched for sample code that was more than what I have but no luck.
I have no trouble using ExtractAssociatedIcon and adding to ListView.
I have tried all types of variations without luck,
Code: Select all
UINT ico_count;
UINT nIcons;
UnicodeString lpszFile;
int nIconIndex = -1;
HICON * phiconLarge;
HICON * phiconSmall;
HICON icon;
TIcon *ico;
TListItem *item;
lpszFile = fileName;
ico_count = ExtractIconExW(lpszFile.w_str(), nIconIndex, phiconLarge, phiconSmall, nIcons);
ico = new TIcon();
ico->Height = 32;
ico->Width = 32;
if(phiconSmall > 0)
{
for(int i = 0; i < ico_count; i++)
{
icon = phiconSmall[i];
ico->Handle = icon;
ImageList->AddIcon(ico);
item = lv->Items->Add();
item->ImageIndex = ImageList->Count -1;
}
}
for(int j = 0; j < ico_count; j++)
DestroyIcon(phiconSmall[j]);
delete ico;