How To Create Dll Library

Table of contents:

How To Create Dll Library
How To Create Dll Library

Video: How To Create Dll Library

Video: How To Create Dll Library
Video: How-To Create And Use A DLL (Dynamic Link Library) with C+ MSVC Visual Studio 2019 Walkthrough 2024, December
Anonim

DLL is a piece of code stored in files with a.dll extension. A piece of code can be used by other applications, but the library is not an application itself. In essence, dynamically linked libraries are collections of compiled functions. However, such libraries have a number of peculiarities - for example, if some applications are simultaneously executed in the system and they use functions located in the same DLL, then only one of the libraries will be permanently in memory - this method ensures economical use of memory.

How to create dll library
How to create dll library

Necessary

Compiler

Instructions

Step 1

Create a new project in the compiler by sequentially selecting the menu items "File", "New", "Library dll". A project will be created with the following content: "intWINAPI_Dll_Entry_Point (HINSTANCE_hinst_unsignedlong {return 1;}".

Step 2

In addition, there will be a lengthy comment warning that for the library to work, a number of.dlls must be supplied, provided that instances of the String class are used. To import and export from a DLL, you must apply the _import and _export modifiers, respectively. In addition, depending on the version of the compiler, it is allowed to use the new keyword _delspec () with the dllimport and dllexport parameters, respectively.

Step 3

To export functions from the library, you will need one header file with a description of _delspec (dllexport) for the exported function; to import functions into applications, the user will need to install a similar header file, but with a _delspec (dllimport) description, which can cause inconvenience. This problem can be easily solved: add the following to the library header files: “#ifdefined (BUILDDLL); # defineDLL_EXP_declspec (dllexport); # else; #ifdefined (BUILDAPP); # defineDLL_EXP_declspec (dllimport); # else; #defineDLL_EXP; #endif endif.

Step 4

Compile the project. If you press "Run", then after completing the construction, the compiler will display a message about the impossibility of executing the program. The calling application should now be written. In the same directory, create a new project (File / NewApplication), place a button in the form and create an OnClick handler.

Step 5

After that, all that remains is to open the project and add the.lib file from the previous project with the DLL (right-click, "Add" item), and then start the project.

Recommended: