Platform SDK: Win32 API

Role of the Thunk Compiler

The thunk compiler takes a thunk script as input, then produces an assembly-language file that implements one or more thunks. These thunks are code that allows 32-bit code to call 16-bit code and vice-versa. The following steps briefly describe how to use the thunk compiler to create a flat thunk.

To create a flat thunk

  1. Create a thunk script.
  2. Compile the thunk script with the thunk compiler.
  3. Assemble the .ASM file produced by the thunk compiler twice — once for a 16-bit .OBJ file and the second time for a 32-bit .OBJ file.
  4. Create a Win32-based thunk DLL and link it with the 32-bit .OBJ file created in step 3.
  5. Create a 16-bit thunk DLL and link it with the 16-bit .OBJ file created in step 3.

The DLLs you create using these steps implement flat thunks. They can provide multiple thunks. If the DLLs implement thunks from 16-bit code to 32-bit code and thunks from 32-bit code to 16-bit code, you will need to create two thunk scripts, one for each direction.

To use the thunk DLLs, simply call the function you want to use. For example, suppose your Win32-based application is calling MyFunction, which is implemented in a 16-bit DLL. The application calls a function implemented in the Win32-based thunk DLL that in turn calls the thunk function, MyFunction. When MyFunction is called in the 32-bit thunk DLL, the code generated by the thunk compiler calls the MyFunction implemented in the 16-bit thunk DLL.