How to Create DLL Files

DLL files are dynamic-linked library files written and controlled with C++. DLLs make sharing, storing, and saving your code simple. This minHour will show you how to create a DLL file with Visual Studio, the Windows application, or Visual Studio for Mac. Make sure you have “Desktop Development with C++” checked when you install. If you already have Visual Studio but didn’t check that box, you can run the installer again to make sure you do.

Steps

Open Visual Studio.

You can find this in your Start Menu or Applications folder. Since a DLL is a library of information, it is only one piece of a project, and usually requires an accompanying app to access it.

  • You can get Visual Studio for Windows here: https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio?view=vs-2019
  • Visual Studio for Mac can be downloaded here: https://docs.microsoft.com/en-us/visualstudio/mac/installation?view=vsmac-2019
  • This wikiHow will be using code provided by Microsoft to explain how to build a DLL file.

Click the File.

You’ll find this either above the project space (Windows) or along the top of your screen (Macs).

Click New and Project.

The “Create a New Project” dialog box will pop up.

Set the options for Language, Platform, and Project Type.

These will filter what kinds of project templates appear.

  • Click Language to get a drop-down menu and click C++.

Click Platform to get a drop-down menu and click Windows.

Click Project Type to get a drop-down menu and click Library.

Click Dynamic-link Library (DLL).

Your choice will highlight blue. Click to continue.

Type a name in the Name Box for the project.

For example, type “MathLibrary” in the box for a sample name.

Click Create.

The DLL project is created.

Add a header file to the DLL.

You can do this by clicking “Add New Item” from “Project” in the menu bar.

  • Select Visual C++ from the left menu of the dialog box.
  • Select Header file (.h) from the center of the dialog box.
  • Type the name as “MathLibrary.h” in the name field below the menu choices.
  • Click Add to generate the blank header file.

Type the following code into the blank header file.

  • This is sample code provided from the Microsoft help website.

Add a CPP file to the DLL.

You can do this by clicking Add New Item from “Project” in the menu bar.

  • Select “Visual C++” from the left menu of the dialog box.
  • Select “C++ File (.cpp)” from the center of the dialog box.
  • Type the name as “MathLibrary.cpp” in the name field below the menu choices.
  • Click Add to generate the blank file.

Type the following code into the blank file.

  • This is sample code provided from the Microsoft help website.

Click Build in the menu bar.

You’ll find this either above the project space (Windows) or along the top of your screen (Macs).

Click Build Solution.

After you click that, you should see text similar to this:

  • If your DLL creation was successful, you’ll see that here. If there was an error, it will be listed here for you to fix.

Leave a Comment