0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by jonason
how to change the default icon with an icon file i want to know !!
Refer to this code.
0
jonason's Avatar
Newbie Member
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!
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
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?
0
pngpas's Avatar, Join Date: Oct 2006
Newbie Member
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);
0
pngpas's Avatar, Join Date: Oct 2006
Newbie Member
BTW, I tried the exe Shabbir posted, not working for me either.
0
pngpas's Avatar, Join Date: Oct 2006
Newbie Member
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;
}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by pngpas
BTW, I tried the exe Shabbir posted, not working for me either.
Did you try downloading the sample source code as well.

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.
0
pngpas's Avatar, Join Date: Oct 2006
Newbie Member
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?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
You are specifying 32528 as the id which may not exist in the final destination. internet explorer it does not exist.
0
JohnnyH's Avatar
JohnnyH
Guest
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