[python-win32] How to use win32api.UpdateResource
cattom
cattom2000 at gmail.com
Sat Apr 30 03:22:02 CEST 2005
I wanted to update some resource in an exe file, then I wrote some procedure
like this:
def updateStringTable...
....
try:
def win32_uc(text):
return unicode(text, "unicode-escape").encode("utf-16-le")
ruUpdateContent = win32_uc(updateContent)
fmt = "h%ds" % len(ruUpdateContent)
updateSection = struct.pack(fmt, len(ruUpdateContent)/2,
ruUpdateContent) + \
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
updateRes = win32api.BeginUpdateResource(self.file, False)
win32api.UpdateResource(updateRes, win32con.RT_STRING, 1,
updateSection, wLanguage)
win32api.EndUpdateResource(updateRes, False)
return True
except win32api.error:
return False
....
When I ran it, this function named "updateStringTable" returned True. It
seems that everything was ok, but the StringTable was unchangeable when I
saw it again. But I wrote same manner procedure by VC6.0 like this:
...
HANDLE hUpdateRes = BeginUpdateResource( _T("UpdateResource.exe"),
FALSE );
BYTE pRes[] = {
0x4, 0x0, 'H', 0x0, 'a', 0x0, 'h', 0x0,
'a', 0x0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
UpdateResource( hUpdateRes, RT_STRING, MAKEINTRESOURCE(1), 2052, pRes,
sizeof(pRes) );
EndUpdateResource( hUpdateRes, FALSE );
...
It worked fine. What's wrong with my python procedure? Thanks for your
reply.
Btw: Python version:2.4.1, Pywin32 Version:Build204 for 2.4
More information about the Python-win32
mailing list