Sample Message Text File
The following sample message file shows how to create and use a message text file that defines messages in multiple languages.
Sample Message File
The following is the sample message file, Sample.mc. It contains a comment block, followed by a header section, followed by messages in two languages. Be aware that you must use a Unicode-compatible editor to simultaneously support the characters used in different written languages. For more information and a detailed description of the syntax of .mc files, see Message Text Files.
; // ***** Sample.mc *****
; // This is the header section.
MessageIdTypedef=DWORD
SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS Informational=0x1:STATUS_SEVERITY_INFORMATIONAL Warning=0x2:STATUS_SEVERITY_WARNING Error=0x3:STATUS_SEVERITY_ERROR )
FacilityNames=(System=0x0:FACILITY_SYSTEM Runtime=0x2:FACILITY_RUNTIME Stubs=0x3:FACILITY_STUBS Io=0x4:FACILITY_IO_ERROR_CODE)
LanguageNames=(English=0x409:MSG00409)LanguageNames=(Japanese=0x411:MSG00411)
; // The following are message definitions.
MessageId=0x1Severity=ErrorFacility=RuntimeSymbolicName=MSG_BAD_COMMANDLanguage=EnglishYou have chosen an incorrect command..Language=Japanese
.
MessageId=0x2Severity=WarningFacility=IoSymbolicName=MSG_BAD_PARM1Language=EnglishCannot reconnect to the server. .Language=Japanese
.
MessageId=0x3Severity=SuccessFacility=SystemSymbolicName=MSG_STRIKE_ANY_KEYLanguage=EnglishPress any key to continue . . . %0 .Language=Japanese
.
MessageId=0x4Severity=ErrorFacility=SystemSymbolicName=MSG_CMD_DELETELanguage=EnglishFile %1 contains %2 which is in error .Language=Japanese
.
MessageId=0x5Severity=InformationalFacility=SystemSymbolicName=MSG_RETRYSLanguage=EnglishThere have been %1!d! attempts with %2!d!%% success%! Disconnect from the server and try again later. .Language=Japanese
.
Building the Message File and DLL
To build Sample.mc, use the following command:
mc -u -U sample.mc
The message compiler generates the following files: Sample.h, Sample.rc, MSG00001.bin, and MSG00002.bin. Sample.h contains the message definitions. Sample.rc defines MSG00001.bin and MSG00002.bin as resources that contain messages in the two languages.
Next, use the resource compiler to build the resource strings as follows:
rc -r sample.rc
Finally, use the resulting Sample.res file to build a resource-only DLL.
link -dll -noentry -out:msgs.dll sample.res
The file Msgs.dll contains the RT_MESSAGETABLE type resource strings.
Using the Message Strings in the Application
The application should include Sample.h and call the LoadLibrary function to load Msgs.dll. To retrieve and use the message text, use the FormatMessage function.
#include <windows.h>
#include <sample.h>
#define BUFSIZE 256
HANDLE ghResDll;
char lpMsgBuf1[BUFSIZE];
char lpMsgBuf2[BUFSIZE];
ghResDll = LoadLibrary("msgs.dll");
// Retrieve the English message string.
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE,
ghResDll,
MSG_BAD_COMMAND, // defined in sample.h
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPTSTR) &lpMsgBuf1,
BUFSIZE,
NULL);
// Retrieve the Japanese message string.
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE,
ghResDll,
MSG_BAD_COMMAND, // defined in sample.h
MAKELANGID(LANG_JAPANESE, SUBLANG_NEUTRAL),
(LPTSTR) &lpMsgBuf2,
BUFSIZE,
NULL);
Send comments about this topic to Microsoft
Build date: 5/7/2009