Applications frequently need to add, delete, or replace resources in executable files. There are two methods to accomplish these tasks. One is to edit the resource-definition file, recompile the resources, and add the recompiled resources to the application's executable file. The alternate method is to copy the resource data directly into the application's executable file.
For example, to localize a U.S. application for use in Norway, it may be necessary to replace the U.S. English dialog box with a Norwegian dialog box. If no Norwegian equivalent of the dialog box is available in another application, you must create a Norwegian dialog box in the resource-definition file, recompile the resources, and add the new resources to the application's executable file.
However, if an appropriate dialog box exists in another executable file, you can obtain a pointer to the dialog box data and copy the data directly to the executable file you are trying to localize.
This process is made possible by three Win32 functions: BeginUpdateResource, UpdateResource, and EndUpdateResource. The BeginUpdateResource function creates an update handle for the executable file whose resources are to be changed. The UpdateResource function uses this handle to add, delete, or replace a resource in the executable file. The EndUpdateResource function closes the update handle.
An application can use UpdateResource repeatedly to make many changes to the resource data. Note that each call to UpdateResource actually contributes to a list of additions, deletions, and replacements, but does not actually write the data to the executable file. EndUpdateResource writes the accumulated changes to the executable file immediately prior to closing the update handle.
The LoadLibrary function provides a module handle to an executable file whose resources you wish to copy, while the LockResource function provides a pointer to the resource data within the specified module. The SizeofResource function returns the size, in bytes, of a specified resource.