I want to change icon on remote exe with one that is stored in RC_DATA in my original program (exe)

I'm using VC6

where is the error?

here's the code

HINSTANCE hExe = LoadLibrary(nameExe);
// first icon
HRSRC hRes = FindResource(NULL, MAKEINTRESOURCE(101), RT_GROUP_ICON);
HGLOBAL hResLoad = LoadResource(NULL, hRes);
PBYTE lpResLock = (PBYTE) LockResource(hResLoad);
int nID = LookupIconIdFromDirectory(lpResLock, TRUE );

HRSRC hRes2 = FindResource(NULL, MAKEINTRESOURCE(nID), MAKEINTRESOURCE(RT_ICON));
HGLOBAL hResLoad2 = LoadResource(NULL, hRes2);
PBYTE lpResLock2 = (PBYTE) LockResource(hResLoad2);

//second icon
HRSRC hRes3 = FindResource(NULL, MAKEINTRESOURCE(102), RT_GROUP_ICON);
HGLOBAL hResLoad3 = LoadResource(NULL, hRes3);
PBYTE lpResLock3 = (PBYTE) LockResource(hResLoad3);
int nID1 = LookupIconIdFromDirectory(lpResLock3, TRUE );

HRSRC hRes4 = FindResource(NULL, MAKEINTRESOURCE(nID1), MAKEINTRESOURCE(RT_ICON));
HGLOBAL hResLoad4 = LoadResource(NULL, hRes4);
PBYTE lpResLock4 = (PBYTE) LockResource(hResLoad4);
	
HANDLE hUpdateRes = BeginUpdateResource(nameExe, FALSE );
				
UpdateResource(hUpdateRes, RT_GROUP_ICON, MAKEINTRESOURCE(101),MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL) , lpResLock4, SizeofResource(hExe, hRes4));
EndUpdateResource(hUpdateRes, FALSE);

where is the error?

Edited 6 Years Ago by suncica2222: n/a

icons etc are loaded using a seperate resource.rc file which looks somethings like this

IDR_APP_ICON ICON "iconname.ico"

I might have missunderstood your question though.

Edited 6 Years Ago by usagi: n/a

I'm not sure what you mean with "remote exe", remote as another place on your machine or remote as in on another computer?

If it's just some other place on your computer and you know where to open it how about reading the file as binary and re-write the part that contains the icon?
To know what to change and how it looks you first create a copy of the remote exe and replace the icon with the one you want in using a resource editor, then you compare the two files and store those changes to your main program.

This article has been dead for over six months. Start a new discussion instead.