Click here to Skip to main content
13,291,084 members (58,280 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 21 Dec 2005

Selectively copy resources between binary (EXE/DLL) files

, 21 Dec 2005
Rate this:
Please Sign up or sign in to vote.
A small program to selectively copy resources from a binary (EXE/DLL) file into a target binary (EXE/DLL) file. Can be used for resource based localization purposes.

Sample Image


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.


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().


Shouldn't have any update since it's a small utility program and you can modify it for your own purposes.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Hao Hu
Software Developer
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

Generalquestion Pin
danamaria20-Oct-06 5:46
memberdanamaria20-Oct-06 5:46 
GeneralRe: question Pin
Hao Hu20-Oct-06 13:06
memberHao Hu20-Oct-06 13:06 
GeneralHi, I am quite interested in your topic Pin
xiongzhend19-Sep-06 21:50
memberxiongzhend19-Sep-06 21:50 
GeneralRe: Hi, I am quite interested in your topic Pin
Hao Hu19-Sep-06 23:26
memberHao Hu19-Sep-06 23:26 
GeneralRe: Hi, I am quite interested in your topic Pin
Portatofe2-Oct-08 7:12
memberPortatofe2-Oct-08 7:12 
GeneralDialogs not copied Pin
bruce.james21-Mar-06 14:59
memberbruce.james21-Mar-06 14:59 
GeneralRe: Dialogs not copied Pin
Hao Hu22-Mar-06 10:24
memberHao Hu22-Mar-06 10:24 
GeneralRe: Dialogs not copied Pin
bruce.james22-Mar-06 11:58
memberbruce.james22-Mar-06 11:58 
GeneralRe: Dialogs not copied Pin
Hao Hu22-Mar-06 12:49
memberHao Hu22-Mar-06 12:49 
GeneralRe: Dialogs not copied Pin
bruce.james22-Mar-06 14:54
memberbruce.james22-Mar-06 14:54 
GeneralRe: Dialogs not copied Pin
Hao Hu22-Mar-06 18:02
memberHao Hu22-Mar-06 18:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 21 Dec 2005
Article Copyright 2005 by Hao Hu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid