Creating and embedding message tables with the WDK/build.exe

Posted on

Although message tables play an important role in Windows, their tool support has always be somewhat limited – at least compared to string tables, for which Visual Studio even provides a graphical editor.

When in comes to creating and embedding message tables into a binary built with the WDK, documentation is light. However, the WDK tool chain provides support for mc files and using it requires only a few steps.

1. Create a message file

Unsurprisingly, the first step is to write a message file – I will name it foobarmsg.mc. Here is an example file:

    ;
    ; The default is NTSTATUS -- but HRESULT works just as well.
    ;
    MessageIdTypedef=HRESULT
    
    SeverityNames=(
      Success=0x0
      Informational=0x1
      Warning=0x2
      Error=0x3
    )
    
    FacilityNames=(
      Interface=4
    )
    
    LanguageNames=(English=0x409:MSG00409)
    
    ;//--------------------------------------------------------------------
    MessageId		= 0x9000
    Severity		= Warning
    Facility		= Interface
    SymbolicName	= FOOBAR_E_WEIRDFAILURE
    Language		= English
    Some weird failure has occured.
    .
    

Updating the SOURCES file

The message file must be compiled (done by mc.exe). If we include the mc file in the SOURCES macro, build.exe will arange this for us:

    SOURCES=
    	foobar.c 
    	foobarmsg.mc
    

To tell mc where to place the result files (i.e. the header and the resources), the following two macros can be used in the SOURCES file:

    PASS0_HEADERDIR=....include
    PASS0_SOURCEDIR=obj$(BUILD_ALT_DIR)$(TARGET_DIRECTORY)
    

As the names of the macros suggest, mc.exe is run during pass 0 (i.e. before any sources are compiled) – therefore, it is no problem to include the generated header file (foobar.h) in the source files.

Updating the rc file

Assuming the project already includes a .rc file for versioning information, we can use this file and refer to the generated message table resources. At the end of your project’s rc file, include the following line:

    #include "foobarmsg.rc"
    

That’s it. The resulting binary will contain a proper message table.

« Back to home