How to extract an icon from executable and save it on disk properly? Any lightweight library?

youki 996 Reputation points
2024-01-20T12:01:43.6833333+00:00

Is there something in c++? (Windows API/ WinRT) I've tried some solutions online and none of them work. I didn't find anything useful on Github either. I want to display the icons regardless of whether the exe is still there, so I want to save the icon; only 1 size is enough. (I think the difficult part is saving the HIcon, I can't find anything about the process.)

Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
725 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,529 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 81,726 Reputation points
    2024-01-20T14:30:04.0333333+00:00

    SaveIconToFile from https://github.com/Skight/wndspy/blob/b89cc2df88ca3e58b26be491814008aaf6f11122/Source/Contrib/SaveIcon.cpp works for me (tested on Jumbo icon of Notepad (SHGetFileInfo with SHGFI_SYSICONINDEX + SHGetImageList with SHIL_JUMBO )