Document home

Visual C++

Visual C++ Localization and Internationalization

Visual C++ (Wikipedia) is a popular Windows development IDE. Soluling localization tool and service support Visual C++.

MFC

 

Portable Executable

Windows EXE and DLL files use the same file format. It is called Portable Executable (PE) file format (Wikipedia).

PE File

Similar file formats are ELF that is used in Linux, and Mach-O that is used in OS X and iOS.

EXE and DLL files

 

Resource DLL

Resource DLL is a special kind of PE file. It does not contain any code but only resource data. Resource DLLs are used to store localized resources. You can not run a resource DLL but it is alway used by the original PE file (exe or dll). By using resource DLLs you can save disk space and what is more important the application can choose the initial language it uses when it starts.

Resource DLL

 

EXE + resource DLL

 

EXE + resource DLLs

 

Initial language of a MFC (Visual C++) application

If you use MFC and version 7.0 later you can take use MFC's automatic resource DLL loading.

MFC attempts to load the resource DLL for each of the following languages in order, stopping when it finds one:

  1. The current user's default UI language, as returned from the GetUserDefaultUILanguage() Win32 API.
  2. The current user's default UI language, without any specific sublanguage (that is, ENC [Canadian English] becomes ENU [U.S. English]).
  3. The system's default UI language. On Windows 2000 or later, this is returned from the GetSystemDefaultUILanguage() API. On other platforms, this is the language of the OS itself.
  4. The system's default UI language, without any specific sublanguage.
  5. A fake language with the 3-letter code LOC.

If MFC does not find any satellite DLLs, it uses whatever resources are contained in the application itself.

Windows

Windows (Wikipedia) application is a file that has EXE file extension. In addition of an EXE file it can contain any number of dynamic library files (.DLL). The format of EXE and DLL file is the same Windows Portable Executable, PE, (Wikipedia). A PE file contains compiled code and resources. You can not change the compiled code after it has been compiled from source code but it is possible to change the resource data. Soluling's Windows localization is based on changing of resource data inside the PE file.

The following picture shows the structure of a PE file. It contains two segments: compiled code segment and resource segment. The resources are in English.

C:\Sample\Application.exe

If we want to localize this application into German we need to replace the English resources with German ones.

C:\Sample\de\Application.exe

The important thing here is that the code segment is exactly the same as in the original English PE file. Only the resource segment has been modified. It contains the same resource items as the original fiel but each item contains German data (e.g. German text). In the same way if we want to localize the application into French we need to replace the resources with French ones.

C:\Sample\fr\Application.exe

In the above sample we copied the origianal PE file and replaced the resources inside the PE file. This is the simplest way to localize Windows applications. The only thing you have to do is to properly internationalize your application. If you have already done it you don't have to change your source code. You don't have to even recompiled your application. This method is the default localization method of Windows application in Soluling.

There is another way to localize Windows application. Instead of coping the PE file itself we can copy only the resource data and store it inside a resource DLL. It is a special DLL that contains no code but only resource data.

The format of the DLL is still Windows PE file but it contains only resource data. It can not be started but the application can load and use its resources instead of the resources of the application file.

If you deploy the original application (e.g. C:\Sample\Application.exe) and the German resource DLL (e.g. C:\Sample\Application.DEU) the application has two choices where to load the resources: either from application file itself or from German resource DLL. What choice to use depends on the application, framework and the operating system where you run the application. In most cases the framework you use (e.g. MFC or VCL) automatically looks for a resource DLL matching the system locale of the computer. However you can add your own code that makes the decision what resource DLL to load. Soluling comes with lots of code to access resources and even perform runtime language switch.

The following sample contains the original application file and three resource DLLs. This makes it possible to start the same application either in English, German, French or Japanese.

If your application is written in Delphi and you have added Soluling's NtTranslator unit into your application the above application can start in any above language and the user can change the language on run time.

Windows development tools

There are several development tools for Windows. Most important are:

Compiler Description Resources Is compiler supported
Visual C++ Microsoft's C/C++ development tool. Standard Windows resources and
optionally MFC resources
Fully supported
Delphi Embarcadero's Pascal based RAD develpment tool. Standard Windows resources and
VCL form resources
Fully supported from Delphi version 7.
Delphi 2-6: Not officially supported but can be used to localize most applications written in these older 32-bit Delphi.
C++Builder As Delphi but uses C++ as programming languages instead Pascal, Standard Windows resources and
VCL form resources
Not officially supported but because C++Builder uses same resource format as Delphi most C++Builder applications can be localized.