Exe file icon change. Icon taken from SHELL32.dll
I need to change some exe files icon using my program. I've found some info and sample codes in MSDN and websites but i'm still in same place.
I need to extract icon from SHELL32.dll
开发者_开发知识库uInt = ExtractIconEx("%SystemRoot%\\system32\\SHELL32.dll" , -63008, &hIcon, NULL, 1);
Then update some exe file resources. But here my problems starts. I don't know how to use HICON returned by ExtractIconEx() function as a parameter of UpdateResource() function.
Here's function code:
void ChangeFileIcon(char * file)
{
HICON hIcon;
UINT uInt;
HANDLE hFile;
LPVOID lpResLock;
uInt = ExtractIconEx("%SystemRoot%\\system32\\SHELL32.dll" , -63008, &hIcon, NULL, 1);
printf("%d", uInt);
lpResLock = LockResource(hIcon);
if (lpResLock == NULL){
printf("LockResource fail ;s\n");
return ;
}
hFile = BeginUpdateResource(file, false);
if(hFile == NULL){
printf("hFile == NULL - error %d\n", GetLastError());
return;
}
UpdateResource(hFile,
RT_ICON,
MAKEINTRESOURCE(1),
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
lpResLock(?),
SizeofResource(????, ????)););
EndUpdateResource(hFile, FALSE);
}
There is example from MSDN but it didn't help me at all: http://msdn.microsoft.com/en-us/library/ms648008%28v=vs.85%29.aspx#_win32_Updating_Resources (in this sample resource from one exe is copied to another)
Thank You for answers, Bury
You can't use a HICON in this case, a HICON is a single image in a specific size and color depth, but a "real" icon resource is usually a collection of images (16x16, 32x32 etc)
Don't use ExtractIconEx, switch to LoadLibraryEx (and use one of the load as data file flags) and then use FindResource[Ex] to find the icon resource.
精彩评论