Обновление иконки exe не срабатывает
Программа выполняется без ошибок, но иконка не обновляется. Пробовал и перезагружать компьютер, и очищать кэш иконок - иконка не меняется.
#include <Windows.h>
#include <iostream>
HGLOBAL hResLoad; // handle to loaded resource
HMODULE hExe; // handle to existing .EXE file
HRSRC hRes; // handle/ptr. to res. info. in hExe
HANDLE hUpdateRes; // update resource handle
LPVOID lpResLock; // pointer to resource data
BOOL result;
int main() {
hExe = LoadLibrary(TEXT("calc.exe"));
if(hExe == NULL)
{
printf("Error loading executable\n");
return -1 ;
}
int res_id = 0;
for (;;res_id++)
{
hRes = FindResource(hExe, MAKEINTRESOURCE(res_id),RT_ICON);
if (hRes == NULL)
{
continue;
}
else
{
break;
}
}
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
printf("Could not load resource\n");
return -1 ;
}
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
printf("Could not lock resource\n");
return -1 ;
}
hUpdateRes = BeginUpdateResource(TEXT("test.exe"), FALSE);
if (hUpdateRes == NULL)
{
printf("Could not open update resource handler\n");
return -1 ;
}
result = UpdateResource(hUpdateRes,RT_ICON,MAKEINTRESOURCE(res_id),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),lpResLock,SizeofResource(hExe, hRes));
if (result == FALSE)
{
printf("Could not begin update resource\n");
return -1 ;
}
if (!EndUpdateResource(hUpdateRes, FALSE))
{
printf("Could not end update resoruce\n");
return -1 ;
}
if (!FreeLibrary(hExe))
{
printf("Could not free resources\n");
return -1 ;
}
printf("Successfully changed icon!\n");
return 0;
}
Кто знает почему такое может быть?