Creating a Resource DLL

Server Appliance Kit

Creating a resource DLL requires that you complete the following eight steps:

  1. Write a message (.mc) file containing the specific messages.

    • Depending on the application, it makes sense to assign facility names to the message file, as illustrated in the following code snippet. System (0x0FF) and application (0xFFF) facilities are supplied by default.

      FacilityNames=(
      System=0x0FF
      Application=0xFFF
      MyApp_tab=0xA00 :SA_MYAPP_FACILITY_TAB
      ) 
      

    • Assign message identifiers to the messages, as illustrated in the following code snippet. This will ensure that message identifiers remain constant even if the message file is later modified. To enable adding messages at a later date, Microsoft recommends that you skip numbers as you assign message identifiers. Assign a symbolic name to each message; the name can then be used within your calling program to extract messages from the dynamic-link library (DLL). Note that at the end of each message entry, a period and a carriage return are required on a separate line.

      MessageID    = 4
      Severity     = Informational
      Facility     = MyApp_Tab
      SymbolicName = SA_MY_TAB_CAPTION
      Language     = English
      My Tab
      .
      

  2. Use the message compiler to compile the message file.

    mc -U -h . -r .      sampleresource.mc
    

    The following table shows the files that the compilation will generate.

    File Description
    MSG00001.bin Binary message (.msg) file that will be included in the resource DLL.
    sampleresource.h Header (.h) file that includes the generated messages and corresponding identifiers. This header file must be included by a calling program that will extract message identifiers that use symbolic names.
    sampleresource.rc Resource file used to generate the DLL.
  3. Create an .rc file that includes the resource file generated by the message compiler. The following code example shows how to create the .rc file.

    /////////////////////////////////////////////////////////////////////////////
    //
    // Message TABLE="100%" Info
    //
    /////////////////////////////////////////////////////////////////////////////
    #include "SampleResource.rc"

#define VER_FILETYPE                    VFT_DLL #define VER_FILESUBTYPE                 VFT2_UNKNOWN #define VER_FILEDESCRIPTION_STR         "Microsoft Server Appliance SDK Sample" #define VER_INTERNALNAME_STR            "SAMPLERESOURCE.DLL" #define VER_ORIGINALFILENAME_STR        "SAMPLERESOURCE.DLL"

  1. Write the source file, called SampleresourceMain.cpp, containing DLLMain as the following code sample illustrates.
    #include "windows.h"

extern "C" BOOL WINAPI DllMain(     HINSTANCE hInstance,     DWORD     dwReason,     LPVOID     lpReserved     ) {         return (TRUE); } // end of DllMain method

  1. Create a definition (.def) file for the DLL. The following code sample shows how to create the .def file.

    ; MyAppResource.def : Declares the module parameters.
    LIBRARY      "SampleResource.dll"
    VERSION 1.0
    EXPORTS
    DllMain         @1 PRIVATE
    

  2. Compile the sampleresourcetbl.rc file using the resource compiler. Please note that the l symbol in the .rc file represents the code page. The resulting .res file is going to be packaged into the resource DLL. The following code sample shows how to compile the sampleresourcetbl.rc file.

    rc -l 409 -r -fo sampleresourcetbl.res sampleresourcetbl.rc
    

    For more information about flag definitions, see the Microsoft Web site.

  3. Compile the source file containing the DLLmain and link the source file with the sampleresourcetbl.res and samplersource.def files to create the sampleresource.dll. The following code sample shows how to compile the source file.

    (Compiler options:
    Cl /c /Zel /Zp8 /Gy  /W3 /Gz  /QIfdiv- /QIf /QI0f /GB /Gi- /Gm- /GX-  /GR- /GF -Z7 /D UNICODE /D _UNICODE /Od -I<include path for include files windows.h, and CRT>
    SampleresourceMain.cpp
    )
    

  4. Type the link command. The following code sample shows how to type the link command.

    link /DLL /MACHINE:Ix86 /DEF:MyAppResource.def Sample MyAppresource.obj MyAppresourcetbl.res msvcrtd.lib
    

After you have created a resource DLL, you will need to find the resource identifiers for each message. You can look in the header (.h) file to match each symbolic name to its corresponding identifier. These identifiers are necessary to instruct the framework functions which localized text you want.

For more information on message compiler, see the Microsoft Web site.