Get large icon from a dll or executable (XP+)

To get a large icon from a DLL or executable use SHDefExtractIcon from the shell32.lib

HRESULT SHDefExtractIcon(
_In_ LPCTSTR pszIconFile,
int iIndex,
_In_ UINT uFlags,
_Out_opt_ HICON *phiconLarge,
_Out_opt_ HICON *phiconSmall,
UINT nIconSize
);

This function is supported since Windows XP.

Icon size contains the required size in pixels. Use MAKELPARAM(large icon size, small icon size) macro to get the correct value. Icons will be resized to the requested size. Use 0 to get the default size.

Sample code:

SHDefExtractIcon(L”c:\\Windows\\System32\\shell32.dll”, 0,0, &iconLarge, &iconsSmall, MAKELPARAM(256, 0));

//To check the size, colordeph
ICONINFO iconInfo = { 0 };
GetIconInfo(iconLarge, &iconInfo);
BITMAP bitmap = { 0 };
GetObject(iconInfo.hbmColor, sizeof(BITMAP), &bitmap);

DestroyIcon(smallIcon);
DestroyIcon(largeIcon);

Lastest update in September 2017, inital post in September 2017

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!