In this post I’m going to show you how you can consume .lib and .dll files in your ue4 project. In case you don’t have a library or a dll file hanging around I’m going to show you how to create one and provide some example files that I have created for this post.

This post is going to be divided in the following categories:

  1. Creating a lib file
  2. Consuming the file in your ue4 project
  3. Creating a dll file
  4. Consuming the dll file in your ue4 project

1. Creating a lib file

In order to create a lib file in visual studio search for the expression “Static Libray” and create a new project

Click on image to open in a new tab

In the project that I have created, I added a new header and source file named OrfeasMathLibrary.h and OrfeasMathLibrary.cpp respectively. Here’s the code for them:

The pch header file is a precompiled header generated from Visual studio. So once you have typed in the code above, compile your project in Release and x64 version. Ideally, you should compile your project in all the different scenarios that you will be building your ue4 project in order to maintain compatibility. This means maybe including debug and x32 versions as well

Once you compile your project in x64 version, the following file will be generated in your visual studio’s project directory: [Visual_Studio_Project_Directory] -> x64 -> Release -> NameOfSolution.lib

You should keep in mind the location of that file since we will need to reference in the ue4 project in the next step

2. Consuming the .lib file

In order to consume the lib file we have created above, first of all, navigate to your ue4 project in the .Build.cs file and add the following line:

Then, in order to call the “Add” function from your .lib file, create a new blueprint function library and type in the following code in the header file:

Afterwards, in its source file, include the header file “OrfeasMathLibrary.h” (or make sure to match the name of C++ class in the lib file).

Then, type in the following implementation for the PrintSumFromLib function:

At this point, you can call the function from anywhere in your Blueprints and see the result coming from the .lib file! Moreover, intellisense should be able to pick up these functions and provide helpful tips.

3. Creating a .dll file

In order to create a dll file, from visual studio select either the dynamic-link library with exports or dynamic-link library.

In case you select the first one, visual studio is going to generate some template code for you. You can either build on top of that or type in your own code.

In my case, here is the header file for my project:

The reason we’re typing MATHISFUNDLL_API before the exposed functions is to mark them as __declspec(dllexport) meaning that we want to make them visible to the application that is consuming our dll. For more information regarding the use of extern C please take a look at the comments above and follow the provided link.

At this point we’re done with the header file so let’s proceed on typing in the logic for the mentioned functions above:

At this point, set your solution configuration to Release and your platform to x64 and you can close visual studio after compiling. Once we’re done with that it’s time to consume the produced dll from the engine

4. Consuming dll files

The process of consuming dll files requires the following three steps:

  1. Creating a dll handle that points to the dll we want to consume
  2. Creating a dll export that is pointing to the function of the dll we would like to use
  3. Calling the pointing function

Heading over to the same Blueprint Function Library that I created before, I’ve added the following code:

Then, on the source file:

At this point, once we compile we can call the functions Sum and GetFibonacciNTerm from our dll file via either C++ or Blueprint code:

Of course you can write up more complicated functions and logic but this post showcases the basic setup for consuming lib and dll files. At this point I would like to thank Rama and ZKarmaKun for their invaluable help. Thanks for reading!