VS2015 C ++ to create and use a dynamic library

 

Reprinted: https://blog.csdn.net/w_x_myself/article/details/82252646

1.dll features

Code reuse is an important way to improve software development efficiency. In general, as long as a part of the code is universal, it can be configured as a relatively independent function modules and reused after the project. More common example is the various application framework, ATL, MFC, etc., which are published in the form of source code. Since this multiplexing is "source level", the source code is completely exposed to the programmer, so called "white box reuse." "White box multiplexing" more shortcomings, summed up the four points. 
   Exposing the source code;

   Multiple copies, resulting in a waste of storage; 

   Naming conflict prone and Programmer of "normal" Code; 

   Update function module is difficult, is not conducive to problem modular realization; 
in fact, more than four points summed up as "exposed source code" cause "serious couples the code." To address these deficiencies, he proposed a "binary level" code reuse. Using the binary level code reuse hide the source code to some extent, for ease of code coupling phenomenon played a certain role. Such multiplexing is referred to as a "black box reuse." 

Description: achieve a "black box reuse" approach not only dll one of the static link library even more advanced COM components are.

2.VS create a new blank solution (a solution can have a lot of project under the program)

2. Create a dll

------ File> New ------> Project ------> Win32 Console Application ------>

 Select dll - check the exported symbols - do not check the precompiled header file

Delete stdafx.h, stdafx.cpp, targetver.h, dllmain.cpp, the MyDll.h modified to dllexport.dll. Modify MyDll.epp in #include "stdafx.h" #include "MyDll.h" changed to "dllexport.h"

 

If the production and use of dll dll project in a solution, we can specify the output directory dll

 

 $ (SolutionDir) --- Solutions Directory

 $ (Platform) ---- platform directory (x86 / x64)

 $ (Configuration) --- compilation mode (Debug / Release)

Because the library is a function of the dll, lib there is a function declaration, we also specify the output path his

 This is what we compile the project:

Then build the bin and lib directories in the Solutions Directory

3. Create a project useDll

Using dll

Import header file specified import

 

Before you run the exe we want to specify the output directory of the project UseDll

 

 operation result:

Dll library to use to configure the project properties

Project - Properties - Configuration Properties - Linker - General - Additional Library Directories: add lib file storage directory. 
Then add a project reference to the lib file name: Project - Properties - Configuration Properties - Linker - Input - Additional Dependencies: add lib file name.

 

 

 

Guess you like

Origin www.cnblogs.com/chechen/p/11415104.html