Tech Support > Microsoft Windows > Development Resources > UpdateResource fails without error
UpdateResource fails without error
Posted by Gernot Frisch on December 3rd, 2003


Hi,
I want to read the RT_VERSION resource from an .exe file and change
the FILEVERSION and PRODUCTVERSION entires. But somehow it doesn't
work. I can load and copy the resource to memory, but when trying to
UpdateResource, the WinExplorer/Properties doesn't show any "Version"
Tab anymore. It seems to be destroyed.
Please, please help.

-Gernot

// Source code of my app:



int _tmain(int argc, _TCHAR* argv[])
{
HRSRC hResLoad;
HMODULE hExe;
hExe = LoadLibrary(argv[1]);
if (hExe == NULL) {printf("Could not load exe."); return 1;}

struct GF_FILE_INFO // File Version resource
{
BYTE header[40];
VS_FIXEDFILEINFO info;
};

GF_FILE_INFO *verinfo, v2;
HRSRC res;
HGLOBAL hres;

res = FindResource(hExe, MAKEINTRESOURCE(VS_VERSION_INFO),
RT_VERSION);
hres = LoadResource(hExe, res);
verinfo = (GF_FILE_INFO *)((char *)LockResource(hres));

// Duplicate version info - looks good in debugger
memcpy(&v2, verinfo, sizeof(GF_FILE_INFO));
FreeLibrary(hExe);

HANDLE handle = BeginUpdateResource(argv[1], FALSE);
if (!handle) {printf("Can't load: %s\n", argv[1]); return 1;}
if (!UpdateResource(handle, RT_VERSION,
MAKEINTRESOURCE(VS_VERSION_INFO),
LANG_NEUTRAL, &v2, sizeof(GF_FILE_INFO)))
printf ("Failed to UpdateResource\n");

if (!EndUpdateResource(handle, false)) printf("Failed to
EndUpdate\n");
return 0;
}




Post here, don't email. If you feel you have to mail, revert my
forename from:
tonreG.Frisch.at.Dream-D-Sign.de@invalid.com
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com


Posted by Norman Bullen on December 4th, 2003




Gernot Frisch wrote:
I don't have my copy of MSDN ready to hand so I'm going by memory here,
but I think the version resource is actually composed of several
structures, packed one after another. When you replace all of that with
just the contents of your GF_FILE_INFO, the result is not a valid
version resource and Explorer ignores it.

Try getting the size of the original resource with SizeOfResource() and
passing that to UpdateResource(). You'll also need to save a copy of the
whole thing instead of just GF_FILE_INFO.

Norm


Posted by Gernot Frisch on December 4th, 2003


Yes, that way I got it working, but there's some language dependent
stings, too. And I can't get that working since it's terribly
complicated inside.
Anyway, I got it as far as I needed it.
-Gernot




Similar Posts