Microsoft KB Archive/92862

From BetaArchive Wiki
< Microsoft KB Archive
Revision as of 06:08, 20 July 2020 by X010 (talk | contribs) (Text replacement - ".htm|" to "|")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

INFO: Alternatives to Using GetProcAddress() With LoadLibrary()

Q92862



The information in this article applies to:


  • Microsoft Win32 Application Programming Interface (API), used with:
    • Microsoft Windows NT Server versions 3.1, 3.5, 3.51, 4.0
    • Microsoft Windows NT Workstation versions 3.1, 3.5, 3.51, 4.0
    • Microsoft Windows 95
    • the operating system: Microsoft Windows 2000





SUMMARY

When loading a DLL with LoadLibrary(), an alternative to calling GetProcAddress() for each of your DLL entry points is to have the DLL initialization function initialize a global structure or array containing the addresses of these DLL entry points, then call a DLL function from your executable which will return the address of this structure or array to your executable. You can then call your DLL functions via the function pointers in this structure or array.



MORE INFORMATION

The best place to initialize this structure or array of function pointers would be in the DLL_PROCESS_ATTACH code of your DLL's main entry point. The structure or array containing these function pointers must be declared as either a global variable or as dynamically allocated memory (malloc(), GlobalAlloc(), etc.) in your DLL in order for the executable to be able to address this memory properly.

It is also possible, though not as clean, to export the global structure or array of function pointers so that your executable can use the structure or array by name directly in your executable. For additional information on how to declare and export global data in a Win32 DLL, click the article number below to view the article in the Microsoft Knowledge Base:

Q90530 Exporting Data From a DLL

Be careful not to call these DLL functions via the function pointers after the DLL is unloaded via FreeLibrary(). After FreeLibrary() is called, these function pointer addresses are invalid and calling them will result in an access violation.

This technique of returning pointers to DLL entry points is a supported technique and will work on all hardware platforms that Windows NT supports.

Additional query words: 3.10 3.50

Keywords : kbDLL kbKernBase kbOSWinNT310 kbOSWinNT350 kbOSWinNT351 kbOSWinNT400 kbOSWin2000 kbOSWin95 kbDSupport kbGrpDSKernBase
Issue type : kbinfo
Technology : kbAudDeveloper kbWin32sSearch kbWin32API


Last Reviewed: December 16, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.