The stages to do so are:
1. Load executable
2. Find resource
3. Load resource
4. Lock resource
5. Begin update resource
6. Update resource
7. End update resource
8. Clean up
Let's go step by step:
1. Loading executable:
hExe = LoadLibrary(Where);
if(hExe == NULL)
{
printf("Error loading executable\n");
return -1 ;
}
2. Locating the resource we would like to replace (the Icon)
hRes = FindResource(hExe, MAKEINTRESOURCE(HL),RT_ICON);
if (hRes == NULL)
{
printf("Could not locate icon.\n");
return -1 ;
}
3. Loading the resource
hResLoad = LoadResource(hExe, hRes);
if (hResLoad == NULL)
{
printf("Could not load resource");
return -1 ;
}
4. Locking resource
lpResLock = LockResource(hResLoad);
if (lpResLock == NULL)
{
printf("Could not lock resource");
return -1 ;
}
5. Begin update
hUpdateRes = BeginUpdateResource(What, FALSE);
if (hUpdateRes == NULL)
{
printf("Could not open icon file for writing.\n");
return -1 ;
}
6. Actual update
result = UpdateResource(hUpdateRes,RT_ICON,MAKEINTRESOURCE(PENG),MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),lpResLock,SizeofResource(hExe, hRes));
if (result == FALSE)
{
printf("Could not begin update resource.");
return -1 ;
}
7. End update
if (!EndUpdateResource(hUpdateRes, FALSE))
{
printf("Could not end update resoruce");
return -1 ;
}
8. Clean up.
if (!FreeLibrary(hExe))
{
printf("Could not free resources");
return -1 ;
}