INF: Making a Callback When Using Generic Thunks
PSS ID Number: Q108229
Article last modified on 04-23-1994

3.10

WINDOWS NT


----------------------------------------------------------------------
The information in this article applies to:

 - Microsoft Win32 Software Development Kit (SDK) for Windows NT
   version 3.1
----------------------------------------------------------------------

SUMMARY
=======

Generic Thunks are provided so that a 16-bit application can load and use a
32-bit dynamic-link library (DLL) under Windows NT. To see a simple example
using Generic Thunks, please see the following article(s) in the Microsoft
Knowledge Base:

   ARTICLE-ID: Q104009
   TITLE     : Calling a Win32 DLL from a Win16 Application Under WOW

This article extends this sample a step further and shows one way in which
you might implement a callback from a 32-bit DLL to the 16-bit application
that loaded it.

MORE INFORMATION
================

Suppose that you had two functions in a 16-bit application that you wanted
to be able to call from a 32-bit DLL that the application has loaded via
Generic Thunks:

   void MyFunc1( UINT );
   void MyFunc2( UINT );

The following steps can be used to accomplish this task:

1. Define function codes for the two functions and a unique message:

      #define MYFUNC1  1
      #define MYFUNC2  2

      #define WM_APP   WM_USER + 101

2. Have the 16-bit application pass its window handle to the 32-bit DLL.
   Note that it should pass it as a 32-bit value. To convert the window
   handle, simply put 0xffff in the upper word, as follows:

      (DWORD) hWnd | 0xffff0000

3. From the 32-bit DLL, call SendMessage() with:

    - The window handle obtained in step 2.
    - WM_APP.
    - The function code for the function that you wish to call.
    - Any data that you wish to pass to the function.

   For example:

      SendMessage( hWnd, WM_APP, MYFUNC1, dwVar1 );
      SendMessage( hWnd, WM_APP, MYFUNC2, dwVar2 );

4. In the 16-bit application, switch on wParam to determine which function
   to call, similar to the dispatch function used in Universal Thunks, and
   pass the parameter that is contained in lParam:

      case WM_APP:
         switch( wParam ) {¬
            case MYFUNC1:
               MyFunc1( lParam );
               break;
            case MYFUNC2:
               MyFunc2( lParam );
               break;
         }
         break;

Additional reference words: 3.10
KBCagegory: Prg
KBSubcategory: SubSys

=============================================================================

Copyright Microsoft Corporation 1994.
