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)
inApplication 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
references are here
in using LIB
- the program using library includes LIB file before executing itself
- this is why LIB method wastes the memory
- need for 3 main settings
- header file path
- LIB file path
- LIB file name
- structure
- LIB file contains implementation
- the program using LIB can run by itself
- the program using library includes LIB file before executing itself
in using DLL
- the program using library includes DLL file after executing itself
- this can help the program get lighter
- need for 4 main settings
- 3 main settings for LIB method
- locating DLL file into the same path with the executable file
- structure
- LIB file just indicates DLL file and DLL file contains implementation
- the program using DLL cannot run by itself
- the program using library includes DLL file after executing itself