Programming/C+±

cpp-lib-and-dll-on-visual-studio (2/2)

BaeMinCheon 2019. 3. 17. 16:26

cpp-lib-and-dll-on-visual-studio (2/2)

  • previous post covers
    • what LIB and DLL files are
    • how to make LIB files
    • how to use LIB files
  • this post covers
    • how to make DLL files
    • how to use DLL files
    • difference between LIB and DLL
  • environment
    • Windows 10 / Home
    • Visual Studio 2017 / Community

make-dll

  • open Visual Studio and make an empty solution

  • add a new project by selecting Windows Desktop Wizard

  • select Dynamic Link Library (.dll) in Application type: combo box
  • uncheck Precompiled Header radio button

  • you will get the screen like this

  • make a header file and fill with the code above

  • the macro determines whether the program will export DLL or import DLL

  • fill the rest of the header

  • make a source file and fill with the code above

  • build solution and check the generated LIB and DLL files in output directory

use-dll

  • open or make any project easy to include the library
  • I recommend you to make Empty Project for convenience

  • prepare any c/cpp file in the project

  • you should add the LIB project path into Additional Include Directories in project property window
    • the path will be used for including header files
  • in my case, the path is D:\Code\VS2017\practice-dll\MathLibrary

  • now you can include the header file

  • you should add the LIB output path into Additional Library Directories in project property window
    • the path will be used for setting range of including LIB file
  • in my case, the path is D:\Code\VS2017\practice-dll\Debug

  • you should add the LIB file name into Additional Dependencies in project property window
    • the name will be used for including certain LIB file
  • in my case, the name is MathLibrary.lib

  • write the code above and build the solution

  • check the generated executable file in output directory

  • copy the DLL file into where the executable file is

  • debug or run the program and you can see the result

wrap-up