Platform SDK: Win32 API

Creating a Win32-Based Thunk DLL

After you compile the thunk script to create the 32-bit side of the thunk, you must create the Win32-based thunk DLL. To implement the Win32-based thunk DLL, use the following steps:

To implement the Win32-based thunk DLL

  1. Add the entry-point function to your 32-bit DLL's entry-point function (named DllMain by default). This function must call the following function created by the thunk compiler:
    BOOL WINAPI XXX_ThunkConnect32(LPSTR pszDll16, LPSTR pszDll32, 
        DWORD hInst, DWORD dwReason);

    Here is an example of a DLL entry-point function calling XXX_ThunkConnect32:

    BOOL WINAPI DllMain(DWORD hInst, DWORD dwReason, 
        DWORD dwReserved) 
    {
        if( !(XXX_ThunkConnect32( "DLL16.DLL",  // name of 16-bit DLL 
            "DLL32.DLL",                        // name of 32-bit DLL 
            hInst, dwReason)) ) 
        {
            return FALSE; 
        } 
        // Process dwReason. 
     
        Return TRUE;
    } 
  2. Add the following export statement to your 32-bit DLL's .DEF file.
    EXPORTS
    XXX_ThunkData32
  3. Export the function to which you are thunking.
  4. Build the DLL. Be sure to link with the 32-bit .OBJ file created from the thunk script and THUNK32.LIB. The 32-bit .OBJ file contains the code for XXX_ThunkData32, which is a table of function calls that the thunk compiler uses to implement the thunks.