Quote:
Originally Posted by jonasonhow to change the default icon with an icon file i want to know !!
|
Go4Expert Founder
|
![]() |
| 20Aug2006,16:54 | #11 |
|
Quote:
Originally Posted by jonason |
|
Newbie Member
|
|
| 21Aug2006,08:49 | #12 |
|
int szFile;
BYTE *lpBuffer; DWORD dwRead; HANDLE hResource; HANDLE hFile=CreateFile("E:\\aa.ico", GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_N ORMAL,NULL); if (hFile==INVALID_HANDLE_VALUE) return; szFile=int(GetFileSize(hFile,NULL)); lpBuffer = new BYTE[szFile]; ReadFile(hFile,lpBuffer,sizeof(lpBuffer),&dwRead,N ULL); hSrcExe = LoadLibraryEx("E:\\a.exe",NULL, LOAD_LIBRARY_AS_DATAFILE); if(hSrcExe == NULL) return; hRes = FindResource(hSrcExe, MAKEINTRESOURCE(1), RT_ICON); if (hRes == NULL) return; FreeLibrary(hSrcExe); hResource = BeginUpdateResource("E:\\a.exe", FALSE); if (hResource == NULL) return ; result = UpdateResource(hResource,RT_ICON,MAKEINTRESOURCE(1 ),MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),(LPVOID)lpBuffer,sizeof(lpBuff er if (result == FALSE) return ; EndUpdateResource(hResource, FALSE); CloseHandle(hFile); delete[] lpBuffer; it can replace the defaulte icon but can't display the aa.ico in the EXE file ,i don't know the reason can you tell me what's wrong with above codes and give a complete code for this? thanks! |
|
Go4Expert Founder
|
![]() |
| 21Aug2006,10:45 | #13 |
|
Please use the bbcode for codes so that its easy to see and analyze the code.
Also you dont have the correct syntax for the UpdateResource function and line is truncated. Also can you alrify a bit more on what you mean by it can replace the defaulte icon but can't display the aa.ico in the EXE file? |
|
Newbie Member
|
|
| 25Oct2006,02:11 | #14 |
|
Hi,
I tried following code, but it is just not working . Can anybody help me out here?Thanks. Code:
HMODULE hSrc = LoadLibrary(L"C:\\GPSamples\\vmplayer.exe");
if (hSrc == NULL)
{
return 1;
}
HRSRC hRes, hResLoad;
char *lpResLock;
hRes = FindResource(hSrc, MAKEINTRESOURCE(1), RT_ICON);
if (hRes == NULL)
{
return 1;
}
hResLoad = (HRSRC)LoadResource(hSrc, hRes);
if (hResLoad == NULL)
return 1;
lpResLock = (char *)LockResource(hResLoad);
if (lpResLock == NULL)
return 1;
HANDLE hUpdateRes;
hUpdateRes = BeginUpdateResource(L"C:\\GPSamples\\vmnetcfg.exe", FALSE);
if (hUpdateRes == NULL)
{
return 1;
}
if (!UpdateResource(hUpdateRes,
RT_ICON,
MAKEINTRESOURCE(1),
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
lpResLock,
SizeofResource(hSrc, hRes)))
{
return 1;
}
if (!EndUpdateResource(hUpdateRes, FALSE))
{
return 1;
}
FreeLibrary(hSrc);
|
|
Newbie Member
|
|
| 25Oct2006,02:15 | #15 |
|
BTW, I tried the exe Shabbir posted, not working for me either.
|
|
Newbie Member
|
|
| 25Oct2006,09:04 | #16 |
|
I tired following code, doesn't work either
![]() Code:
int main(int argc, char* argv[])
{
HANDLE hIcon = CreateFile("D:\\Samples\\xvid.ico",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (!hIcon)
{
return 1;
}
LPBYTE lpBuf;
DWORD dwFileSize, dwBytesRead;
dwFileSize = GetFileSize(hIcon, NULL);
lpBuf = (LPBYTE)malloc(dwFileSize);
if (!lpBuf)
{
CloseHandle(hIcon);
return 1;
}
ReadFile(hIcon, lpBuf, dwFileSize, &dwBytesRead, NULL);
if (dwBytesRead != dwFileSize)
{
free(lpBuf);
CloseHandle(hIcon);
return 1;
}
CloseHandle(hIcon);
HANDLE hUpdateRes;
hUpdateRes = BeginUpdateResource("D:\\Samples\\iexplore.exe", FALSE);
if (hUpdateRes == NULL)
{
free(lpBuf);
return 1;
}
if (!UpdateResource(hUpdateRes,
RT_ICON,
MAKEINTRESOURCE(32528),
MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
lpBuf, dwBytesRead))
{
free(lpBuf);
return 1;
}
if (!EndUpdateResource(hUpdateRes, FALSE))
{
free(lpBuf);
return 1;
}
free(lpBuf);
printf("Hello World!\n");
return 0;
}
|
|
Go4Expert Founder
|
![]() |
| 25Oct2006,10:38 | #17 |
|
Quote:
Originally Posted by pngpas Also in the code sample you have posted you are not using the FindResource function for all the id's but just for 1. That may not be present in the destination executable. Try using my sample for some other executable as I have looped only till 10 for just a sample. |
|
Newbie Member
|
|
| 25Oct2006,19:39 | #18 |
|
actually, I tried that already, didn't work either. How about the code I posted that reads an icon file? Can you tell what is wrong with it?
|
|
Go4Expert Founder
|
![]() |
| 25Oct2006,19:52 | #19 |
|
You are specifying 32528 as the id which may not exist in the final destination. internet explorer it does not exist.
|
|
Newbie Member
|
|
| 13Dec2006,01:56 | #20 |
|
Hi Shabbir, I have implemented some code that does something similar to your example above except that it copies Version information from one executable's resource information into another executable's resource information. It works as long as both the source executable and destination executable have resource files compiled into them. But the problem I am having is that if the destination executable (the one I want to copy the resources into) does not already have a resource file compiled into it the copy action appears to work (all functions return successfully) but the target executable is no longer runable and the version information that I tried to copy into it is not retrievable. Do you know if it is possible to copy an executable's resources into another executable if the destination executable doesn't have a resource file compiled into it?
Thanks, John |