Make a DLL


Walkthrough: Creating and Using a Dynamic Link Library (C++)

  1. Make two projects: make_dll.prj and use_dll.prj under the solution
  2. Add Microsoft extension attribute to functions and/or classes
    #ifdef MYDLL_EXPORTS
    #define MYDLL_API  __declspec(dllexport)
    #define MYDLL_API  __declspec(dllimport)
    namespace MyLib
        MYDLL_API int foo(int, const char*);
        class MYDLL_API MyClass {
  3. Define MYDLL_EXPORTS in make_dll.prj but not in use_dll.prj
  4. Open use_dll.prj property dialog, choose [Common Properties] [References] and click [Add New Reference …], add reference to make_dll.prj
  5. Build dll (make_dll.prj) and application (use_dll.prj)


Further topics:

export functions from a dll by ordinal rather than by name, using .def files

Exporting C++ classes from a DLL