DLL Basics

General 

  • Bindings
    • Early binding
      • Loaded when program starts
    • Late binding
      • Loaded after program has started
      • Calls LoadLibrary() to load dll
      • Calls GetProcAddress() to get function address
      • Calls FreeLibrary() to to unload dll

Contents

  • Functionis
  • Resources
    • Bitmaps
    • Fonts
  • Static global variables
  • DLL interface
  • DllMain() function

Varieties of DLL

  • MFC extension DLL
  • Regular DLL
    • Statically linked to MFC
    • Dynamically linked to MFC

Create DLL

  • Export class
    • Append AFX_EXT_CLASS to the class specifier
      • class AFX_EXT_CLASS CMyClass {…}
    • Or use the .def file
      • #define DLLEXPORT _declspec(dllexport)
      • DLLEXPORT double avalue = 1.5;
      • DLLEXPORT CString FinWinner(CString* Teams);
  • Add to StdAfx.h (StdAfx is acronym for standard application framework extenstion, later called MFC) 
    • #include <afxtempl.h>
  • Build artifacts
    • MyDll.dll
      • Contains executable code
    • MyDll.lib
      • Contains definitions of item that are exported from DLL
      • Must be avaible to client application linker 

Files required to use DLL

  • .h file
    • Defines items exported from dll
    • Need to be included in the host application 
      • #include “SimpleDll.h”
  • .lib file
    • Used by linker to link host application to dll
    • Need to be included in the Project Link path
      • Project -> Settings -> Link
  • .dll file
    • Contains executable code for the dll
    • Need to be in the system path with all its dependency dlls, e.g. Debug folder or System32 folder
This entry was posted in cpp. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


*

This site uses Akismet to reduce spam. Learn how your comment data is processed.