Platform SDK: Win32 API

Creating a 16-bit Thunk DLL

After you compile the thunk script to create the 16-bit code for the thunk, you must create the 16-bit thunk DLL. To implement the 16-bit thunk DLL, use the following steps.

To implement the 16-bit thunk DLL

  1. Add a function named DllMain to your 16-bit DLL. This function should have the following structure:
    BOOL FAR PASCAL __export DllMain(DWORD dwReason, WORD hInst, 
            WORD wDS, WORD wHeapSize, DWORD dwReserved1, 
            WORD wReserved2) 
    { 
        if( !(XXX_ThunkConnect16( "DLL16.DLL",  // name of 16-bit DLL 
            "DLL32.DLL",                        // name of 32-bit DLL 
            hInst, dwReason)) ) 
        { 
            return FALSE; 
        } 
        return TRUE; 
    } 

    Note that DllMain calls the following function, which was generated by the thunk compiler:

    BOOL FAR PASCAL __export XXX_ThunkConnect16(LPSTR pszDll16, 
        LPSTR pszDll32, WORD hInst, DWORD dwReason); 

    In this example, XXX is the base name — that is, the name of the thunk script file, not including the path and filename extension. If you used the /t option with the thunk compiler to specify a different base name when you compiled the thunk script, use that base name here.

  2. Add the following statements to your 16-bit DLL's module definition (.DEF) file, choosing ordinals appropriate for your DLL.
    EXPORTS
    DllMain             @1 RESIDENTNAME
    XXX_ThunkData16     @2 RESIDENTNAME
    
    IMPORTS
    C16ThkSL01     = KERNEL.631
    ThunkConnect16 = KERNEL.651
  3. Build the DLL. Be sure to link with the 16-bit .OBJ file created from the thunk script. This file contains the code for XXX_ThunkData16, which is a table of function calls the thunk compiler uses to implement the thunks.
  4. Mark the DLL with version 4.0, using the 16-bit resource compiler included with the Platform SDK.
    rc -40 DLL_Name

To ensure that your application works correctly, it is important that you use the following rules when implementing your thunks: