I've been trying to change the icon of an exe programmatically, on Windows. I have a .exe file, and a .ico file, and I want the icon of the .exe to become the .ico file.
I've seen this thread and I'm not too sure about if it is applicable here. That user knew the following: 'the icon the exe uses in the app's .rc file is IDR_MAINFRAME
(ID 128)'. I'm not sure what IDR_MAINFRAME
is exactly or if it's useful in my case (furthermore, I can't even find what #include
is needed for it).
My current code is the following:
HANDLE exe = BeginUpdateResourceW(exe_path, FALSE);
UpdateResourceW(exe,
RT_GROUP_ICON,
RT_GROUP_ICON, // I think this might be the issue?
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
icon, // a .ico file, in memory, as raw binary data
icon_size);
EndUpdateResource(exe, FALSE);
CloseHandle(exe);
I've omitted error-handling code but I am checking the return values of all Windows API calls and they return successfully. I also notice that the .exe in question is updated in some way: it gets a new 'date modified' value, and OneDrive (which I have running in that directory) recognizes the file as modified because it prompts it to upload to the cloud. However, the icon doesn't change, even after restarting Explorer and even when explicitly deleting the icon cache.
I think the issue may be the lpName
parameter of UpdateResourceW
, but I'm not sure exactly what value is meant to go there. As I said above, the previous post had MAKEINTRESOURCE(IDR_MAINFRAME)
but I'm not sure if this is appropriate or how to get IDR_MAINFRAME
.