
Introduction
This program demonstrates how you can selectively copy some resources from other binary (EXE/DLL) files into a target binary (EXE/DLL) file. The best place it can fit in might be in application localization (if the localization is based on resource modification). If you have other nice usages, please share the information with me.
Background
I was assigned to do the localization for a WinXP 64 bit version application (based on resource modification). The guy who did the 32 bit version localization told me I need to manually adjust the dialog box size to avoid cutting off strings for some languages. Basically, I hate this kind of work, so I wanted to find some other solution.
The original idea was: the 32 bit localization was done, why not just dump all 32 bit application resources into a 64 bit program? After I read MSDN for a little while, I found that there were two exciting examples in MSDN, and the combination of them is exactly what I wanted. And I did so.
After I tried to localize the first round, I found I only wanted to selectively copy those localized resources from the 32 bit program. Else I'd end up screwing up something, for instance, the version number.
Using the code
You'll need to run this program from the command line. To get localized resources from Target_LC.exe and put them into Target.exe will roughly be:
CopyRes.exe Target_LC.exe Target.exe
The code itself is very straightforward with comments. Here is an example for those steps inside a C code:
For example, we have : Target_64bit.exe[English Version - EN]
and Target_32bit.exe[Localized Version - LC]
Want to generate: Target_64bit.exe[Localized Version - LC]
Step 1. copy Target_64bit.exe[EN] to Target_64bit.exe.tmp[EN]
Step 2. Use LoadLibraryEx() to load
Target_64bit.exe.tmp[EN] & Target_32bit.exe[LC]
Step 3. Use BeginUpdateResource() to clean all
existing resources in Target_64bit.exe[EN]
Step 4. Foreach Resource Types in Target_64bit.exe.tmp[EN]
if Resource Type is DIALOG/MENU/STRING
// Localized Resources
Use UpdateResource() to copy all that type resources
From Target_32bit.exe[LC] into Target_64bit.exe[EN]
else // Keep other resources
Use UpdateResource() to copy all that type resources
From Target_64bit.exe.tmp[EN] into Target_64bit.exe[EN]
Step 5. Clean up activities.
Comments for some functions
You need LoadLibraryEx
with DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE
flags for maximum compatibilities. For example, if you want to replace a 64 bit application's resources: applying TRUE
to BeginUpdateResource()
will clean the existing resources.
All those callback functions (EnumTypesFunc
, EnumNamesFunc
, EnumLangsFunc
) have a handy extra parameter that can be used for your own purpose.
Points of Interest
You actually not only can copy the resource, but also will be able to modify those resources on the fly. Read more in MSDN. One of the key ideas I learned was: it seems that a system does not allow you to modify the resource memory block (returned from LockResource()
) directly. What I tried was copy that memory block first, then update it inside my own memory block, and then use it as the parameter for UpdateResource()
.
History
Shouldn't have any update since it's a small utility program and you can modify it for your own purposes.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.