SAMPLE: Application Dynamically Links to a DLL Using a Class

Last reviewed: February 15, 1996
Article ID: Q85282
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows version 3.1

The traditional methods an application uses to dynamically link to a dynamic-link library (DLL) in the Windows environment, using the LoadLibrary() and FreeLibrary() functions, can be awkward. The application is required to call GetProcAddress() for each DLL function the application links to, and the application is then required to store the returned address in an array. The source code of the application must also contain a prototype for each called function or the programmer must cast each function parameter to the required type.

The object-oriented techniques of Microsoft C/C++ version 7.0 can be applied to ease the process of dynamically linking with a DLL. An application can define a class that links to the DLL and contains pointers to each of the exported functions. Member functions of the class correspond to the exported functions in the DLL.

DYNDLL is a file in the Microsoft Software Library that demonstrates using a class, called CDynDLL, to dynamically link to a DLL. The CDynDLL constructor loads the library and retrieves pointers to each function exported by the DLL. The CDynDLL destructor frees the library. The member functions of the CDynDLL class correspond to the functions exported by the DLL.

Download DYNDLL.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:

  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download DYNDLL.EXE (size: 26106 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get DYNDLL.EXE (size: 26106 bytes) 
    


Additional reference words: 3.10 softlib DYNDLL.EXE
KBCategory: kbprg kbfile
KBSubcategory: KrFileIO


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: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.