Replace the icon of the EXE Executable File: 1. first obtain the pointer to the source resource; 2. Use the updateresource function to replace it;
// Hmodule Hexe;
Handle hupdateres;
Hrsrc hres;
Handle hresload;
Char * lpreslock;
Bool result;
Hexe = loadlibrary ("a.exe ");
If (! Hexe)
{
MessageBox ("failed to load executable file! ");
}
Hres = findresource (Hexe, makeintresource (idi_icon1), rt_group_icon );
If (! Hres)
{
MessageBox ("findresource failed! ");
}
Hresload = loadresource (Hexe, hres );
If (! Hresload)
{
MessageBox ("loadresource failed! ");
}
Lpreslock = (char *) lockresource (hresload );
If (! Lpreslock)
{
MessageBox ("lockresource failed! ");
} Hupdateres = beginupdateresource ("switch.exe", false );
If (! Hupdateres)
{
MessageBox ("beginupdateresource failed! ");
}
Result = updateresource (hupdateres, rt_group_icon, makeintresource (idr_mainframe ),
Makelangid (lang_neutral, sublang_neutral), lpreslock, sizeofresource (Hexe, hres ));
If (! Result)
{
MessageBox ("updateresource failed! ");
}
If (! Endupdateresource (hupdateres, false ))
{
MessageBox ("cocould not write changes to file .");
}
// Clean up.
If (! Freelibrary (Hexe ))
{
MessageBox ("cocould not free executable .");
}
}