Drivers-DLL under MSVC++!

Idriss Chaouch
2 min readOct 27, 2020

DLL stands for Dynamic Link Library (shared library) and it is useful in many use cases. Let’s start by enumerating its advantages:

Promotes modular architecture:

A DLL helps promote developing modular programs. This helps you develop large programs that require multiple language versions or a program that requires modular architecture. An example of a modular program is an accounting program that has many modules that can be dynamically loaded at run time.

Uses fewer resources:

When multiple programs use the same library of functions, a DLL can reduce the duplication of code that is loaded on the disk and in physical memory. This can greatly influence the performance of not just the program that is running in the foreground, but also other programs that are running on the Windows operating system.

How to create a DLL in Microsoft Visual Studio? Let’s follow these steps carefully:

  1. Launch MVS (Microsoft Visual Studio) and select dll with exports as shown in the picture below, the option with exports is primordial otherwise you will not get the .lib file which will be used lately.
DLL with exports

2. Now add your .c or .cc file with the header that goes with and don’t forget to prefix your functions in both header and source file with PROJECTNAME_API. If you want to use some extern variables you have to do it here and not in the project that you will link it this dll. The below figure shows an example:

Example of header file
Example of a source file

3. Click build and it’s done.

Now create a new project, under MSVC++ and follow the next steps:

  1. Properties >> C/C++ >> General >> Additional Include Directory >> ..\..\SolDirectoryOfTheDLLProject\TheFolderWhichConatinsTheNameOfTheProject (to add the header file you created in the last project)
  2. Properties >> C/C++ >> Linker >> General >> Additional Library Directory >> ..\..\SolDirectoryOfYourCurrentProject\Debug
  3. Properties >> C/C++ >> Linker >> Input >> Additional Dependencies >> add: YourDLLProjectName.lib (and here where dll with exports comes in play, because it will generate that file, a simple dll project will not generate a .lib file.

--

--

Idriss Chaouch

C++ | STL | Semiconductors | VHDL | SoCs | FPGAs | Python | Visual Studio