How To Export Callback Functions

Last reviewed: December 16, 1996
Article ID: Q83706
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT, versions 3.1, 3.5, 3.51, 4.00
        - Microsoft Windows 95, version 4.0
    

SUMMARY

It is not necessary for Win32-based applications to export callback functions. Windows versions 3.1 and earlier (Win16) need callback functions primarily for fixing references to global data and ensuring that EMS memory is not paged out. Neither of these situations applies to the Windows NT operating system.

MORE INFORMATION

Exports are necessary for any function that must be located at either

  • Run time via GetProcAddress()(dynamic linking)

    -or-

  • Load time via an import library (static linking)

Both of these linking methods require that the name or ordinal number of the export be known and that their names (or ordinal numbers) be present in the executable's exported entry table. This enables Windows to determine the addresses at run time.

Static linking is done by the loader, which performs this lookup for all of the imported entry points that an executable needs (normally by ordinal number). In dynamic linking, the system scans by ordinal number or by name through the DLL (Dynamic Link Library) exports table.

In Win16, exported entries are automatically fixed by the linker to adjust to the appropriate data segment. Exporting entries on Win32 just adds them to the module's exported names and ordinal numbers table; the linker does not need to "fix" them. For code compatibility with Win16, you may want to continue to use MakeProcInstance() and export all callbacks. This macro does nothing on Windows NT.

In short,

                    On Windows                       Win32
                    ---------------------------      -----------------

   Callbacks        Export or use MakeProcInstance   Use address of fn
   GetProcAddress   Must export                      Must export
   Static linking   Must export                      Must export


Additional reference words: 3.10 3.50 4.00 95
KBCategory: kbprg kbhowto
KBSubcategory: BseDll


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 16, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.