A dynamic-link library (DLL) is an executable file that acts as a shared library of functions.
There are two ways of linking: static and dynamic linking.
Dynamic linking provides a way for a process to call a function that is not part of its executable code. The executable code for the function is located in a DLL, which contains one or more functions that are compiled, linked, and stored separately from the processes that use them. DLLs also facilitate the sharing of data and resources. Multiple applications can simultaneously access the contents of a single copy of a DLL in memory.
Dynamic linking differs from static linking in that it allows an executable module (either a .dll or .exe file) to include only the information needed at run time to locate the executable code for a DLL function.
In static linking, the linker gets all of the referenced functions from the static link library and places it with your code into your executable.
Using dynamic linking instead of static linking offers several advantages. DLLs save memory, reduce swapping, save disk space, upgrade easier, provide after-market support, provide a mechanism to extend the MFC library classes, support multilanguage programs, and ease the creation of international versions.
We will review both methods of linking.
An executable file links to (or loads) a DLL in one of two ways:
Implicit linking (dynamic linking).
Explicit linking (static linking).
To implicitly link to a DLL, executables must obtain the following from the provider of the DLL:
A header file (.h file) containing the declarations of the exported functions and/or C++ classes. The classes, functions, and data should all have__declspec(dllimport).
An import library (.LIB files) to link with. (The linker creates the import library when the DLL is built.)
The actual DLL (.dll file).
Executables using the DLL must include the header file containing the exported functions (or C++ classes) in each source file that contains calls to the exported functions. From a coding perspective, the function calls to the exported functions are just like any other function call.
All required files for building your own application for DLN-series adapters can be found at '..\Program Files\Diolan\DLN\bin' (contains libraries) and 'Program Files\Diolan\DLN\common' (contains header files) after DLN setup package installation.
To build the calling executable file, you must link with the import library. If you are using an external makefile, specify the file name of the import library where you list other object (.obj) files or libraries that you are linking with.
The operating system must be able to locate the DLL file when it loads the calling executable.
You can connect dln.dll library in Visual Studio project by opening Property Pages Dialog, choosing Linker > Input and adding path string to dln.lib to Additional Dependencies field.
With explicit linking, applications must make a function call to explicitly load the DLL at run time. To explicitly link to a DLL, an application must:
Call LoadLibrary (or a similar function) to load the DLL and obtain a module handle.
Call GetProcAddress to obtain a function pointer to each exported function that the application wants to call. Because applications are calling the DLL's functions through a pointer, the compiler does not generate external references, so there is no need to link with an import library.
Call FreeLibrary when done with the DLL.