Click here to Skip to main content
15,867,895 members
Articles / Desktop Programming / MFC
Article

Build localized apps as separate executables

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
26 Jul 20021 min read 49.1K   614   15   3
How to build a separate executable for each language version.

Sample Image - BuildResSeparately.jpg

Overview

Microsoft Visual Studio 6.0 offers only a framework to build all resources into one executable file. This can be disturbing if you want to localize your application into completely separated files. Fortunately VC++'s wide environment allows you to achieve this with a couple of steps...

Steps:

  1. Rename your default Demo.rc file to Demo_EN.rc or other names depending on the language version.
  2. Create a new default Demo.rc file which would look something like this:
    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    ////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"
    
    ////////////////////////////////////////////////////////////
    #undef APSTUDIO_READONLY_SYMBOLS
    
    #ifdef APSTUDIO_INVOKED
    ////////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
    "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
    "#ifdef MYLANGUAGE_CZ\r\n"
    "#include ""Demo_CZ.rc""\r\n"
    "#endif\r\n"
    "\r\n"
    "#ifdef MYLANGUAGE_EN\r\n"
    "#include ""Demo_EN.rc""\r\n"
    "#endif\r\n"
    "\0"
    END
    
    #endif // APSTUDIO_INVOKED
    
    
    #ifndef APSTUDIO_INVOKED
    ////////////////////////////////////////////////////////////
    //
    // Generated from the TEXTINCLUDE 3 resource.
    //
    #ifdef MYLANGUAGE_CZ
    #include "Demo_CZ.rc"
    #endif
    
    #ifdef MYLANGUAGE_EN
    #include "Demo_EN.rc"
    #endif
    
    ////////////////////////////////////////////////////////////
    #endif // not APSTUDIO_INVOKED
  3. Add the standard resource file (renamed to Demo_EN.rc) into the project (Menu/Project/Add To Project/Files)
  4. Go to Menu/Build/Configurations and add appropriate build configuration (Add... e.g. Release English, Copy from: Release)
  5. Go to Menu/Project/Settings, select your newly added Release English configuration
    • Switch to General tab, change the intermediate and output files location - just enter Release
    • Switch to Link tab and change the output file name to Release/Demo_EN.exe
    • Switch to Resources tab, Resource file name: Release/Demo_EN.res, preprocessor definitions: insert the string MYLANGUAGE_EN, change the Language to English (if not selected)
  6. Follow steps 3-5 for each language version you want to build
  7. For each new language version, add these lines into Demo.rc file:
    "#ifdef MYLANGUAGE_CZ\r\n"
    "#include ""Demo_CZ.rc""\r\n"
    "#endif\r\n"
    "\r\n"
    #ifdef MYLANGUAGE_CZ
    #include "Demo_CZ.rc"
    #endif

Note: For ATL projects you must keep the typelib in Demo.rc:

1 TYPELIB "Demo.tlb"

License

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


Written By
Web Developer
Czech Republic Czech Republic
I've been studying economy for 10 years but naturally I'm software developer (and will still be of course Smile | :) .
My computer experience includes C64, Amiga (assembler), currently C++/MFC/ATL on Windows.


Comments and Discussions

 
QuestionEmbedding Executables? Pin
Lalith Narayan18-Sep-03 11:31
Lalith Narayan18-Sep-03 11:31 
GeneralBe careful with multiple .RCs Pin
Victor Vogelpoel28-Jul-02 2:07
Victor Vogelpoel28-Jul-02 2:07 
GeneralRe: Be careful with multiple .RCs Pin
WREY29-Jul-02 7:47
WREY29-Jul-02 7:47 

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.