The information below discusses how to make a localized resource DLL with Visual C++ 5.0.
- Create a default MFC AppWizard application (called MyApp in this example), and specify U.S. English for the resources language. Use MFC library as a shared DLL.
- Insert a default MFC AppWizard DLL as a top-level project (ResourceDll in this example), and select MFC Extension DLL (using shared MFC DLL) for the type of DLL. Because no .lib file is created for the DLL, a top-level project avoids linker problems in subsequent builds of the executable.
- Remove and delete the RC file, the Resource.h file, the ResourceDll.rc2 file, and the RES directory from the ResourceDll project.
- From the Project menu, select the Add To Project pop-up menu and choose Files. Insert the MyApp.RC file into the ResourceDll project.
- For each additional language that MyApp will have localized resources for:
- From the Build menu, click Configurations and add a new Release and Debug configuration. For example, add a French Release configuration and copy its settings from ResourceDll - Win32 Release and add a French Debug configuration and copy its settings from ResourceDll - Win32 Debug.
- In the Project Settings dialog box, choose Multiple Configurations, in the Settings for combo-box. Choose both the release and the debug project configurations for a particular language in the Select Project Configurations to Modify dialog box. In the Resources tab, add the preprocessor definitions AFX_RESOURCE_DLL and AFX_TARG_XXX, where XXX is the a letter specifier for the language. For example, FRA for French [France, DEU for German, and ENU for English (USA)].
NOTE: The preprocessor definitions are comma separated with no spaces between definitions.
- In the Language combo-box, select the language used in the resource.
NOTE: You may want to name your DLLs to help identify them. For example you may want to add a "d" to the root name to mark it as a debug DLL, and use language-specific file extensions to note the locale. Be aware that a debug version of the executable will not work with a release version of the resource dll.
This can be done by changing the output target that the linker uses for each build of the DLL.
- Select the Link property page from the Project settings dialog box.
- In the in the Settings For combo-box, highlight the configuration for which you want to change the DLL output directory.
- Make sure Category is set to General and specify the output directory name in the edit box under Output File Name.
To use these DLLs, you must copy the desired DLL into the same directory that MyApp.exe is in, or an appropriate Windows directory, and rename it to ResourceDll.dll or ResourceDllD.dll. For example:
You can also specify the directory where the resource file, MyApp.res, will be generated for each localized DLL.
- Select the Resources property page from the Project settings dialog box.
- In the in the Settings For combo-box, highlight the configuration for which you want to change the resource output directory.
- Make sure Category is set to General and specify the directory where the output file for the resources will be generated in the edit box under Resource file name.
- From the Project menu, select Settings and highlight the
ResourceDLL project. Choose All Configurations from the Settings For combo box. Click the C/C++ tab followed by its Preprocessor category. Add the path for the MyApp project in the Additional include directories field.
- From the Project menu, select Settings and highlight the MyApp project. Choose All Configurations from the Settings For combo box. Click the Resources tab, and in the Preprocessor definitions field, add AFX_RESOURCE_DLL. This definition removes all of the resources from MyApp.exe.
- In the ResourceView workspace, open each folder and, with the CTRL key pressed, select all of the resources in the MyApp project. For example, your selections should include an IDR_MAINFRAME for the Accelerator and IDD_ABOUTBOX for the Dialog.
For each of the ResourceDLL configurations, on the Insert menu, click Resource Copy, set the language to the appropriate language, and press OK. You should now have a complete set of resources for anther language. The resources, however, must be translated.
(If the language for which you want to create localized resources is not in the list of languages, select another language and manually edit the text of the resource file. After you have made the appropriate changes, the brackets next to the resource will say "Unknown Language" and show the language and sublanguage identifiers.)
NOTE: You can also copy preexisting resources to the resource file at this time. For example, create a separate MFC AppWizard application project that uses the French language resources by using the same selections you used to create the initial MyApp project. After creating this application, close its workspace and open the MyApp project workspace and select ResourceView. Then, on the File menu, click Open, and open the French application's RC file. Now drag/drop all of the resources from the French application into the MyApp application. These resources are already in French and need no translation.
- Add an HINSTANCE member variable to the application's CWinApp derived class. This will hold the DLL instance handle. For example:
Inside the CWinApp::InitInstance definition for your project, add the following three lines at the top of the function:
// Load the debug version of the localized resources.
m_hInstResDLL = LoadLibrary("ResourceDlld.dll");
// Load the release version of the localized resources.
m_hInstResDLL = LoadLibrary("ResourceDll.dll");
ASSERT( m_hInstResDLL != NULL );
NOTE: It is not necessary to call AfxSetResourceHandle() at this point.
- Add a CMyApp::ExitInstance() member function using the Class Wizard. Add code freeing the library before the application exits. Modify the function as follows:
// In case you load multiple DLL's make sure to free them,
// and avoid calling FreeLibrary with a NULL pointer.
- The application is ready to build. Using the Batch Build dialog box, select the desired targets. Remember that you must copy the appropriate DLL into the a suitable location and rename it.
Tech note 57 (TN057) describes some of the designs and procedures you can use to localize your component, be it an application or an OLE control, or a DLL that uses MFC.
Tech note 23 (TN023) describes the standard resources provided with and needed by the MFC library.
For additional information about the Microsoft Foundation Classes included with Visual C++ versions 2.2 and earlier, please see the following article in the Microsoft Knowledge Base:
(c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Isaac Varon, Microsoft Corporation.
ID articolo: 198846 - Ultima revisione: 22 giu 2014 - Revisione: 1