Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Adding third party DLL path for plugin

I am using a third party dll with import library and .h file , so far I am able to get it working if I place the dll in the binaries folder of the game project , however this is undesirable for a plugin.

but if I move it somewhere else and put the path in the build.cs file then UE4 starts to look for the dll in standard OS locations and hence complains about missing DLL.

How should I add my dll in build.cs so that the plugin knows where to find it (Plugin folder .. thirdparty etc) ?

P.S I'm not using function pointer approach, instead calling function from header file using the import library.

Product Version: UE 4.11
more ▼

asked May 30 '16 at 04:50 PM in C++ Programming

avatar image

Commander Shepard
772 56 80 214

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Ok so to return the help I got from various sources of the community I'll list the procedure for linking a third party dll with import library for a UE4 plugin.

Import library avoids the mess that happens with function pointers instead you can call functions directly using a header

Its mostly straightforward but lack of docs made me confused.

So a DLL with import library will come with three files minimum:

1.The DLL itself

2.The .h header file that declares all the functions of the DLL that you can call

3.The .lib file or import library which contains address of the header file functions in the DLL

For this example my library was called free image , you can find it here Here's what you got to do:

1. In your plugin's build.cs add the following lines:


 PublicAdditionalLibraries.Add(Path.Combine(FreeImageDirectory, "FreeImage.lib"));

Here the FreeImageDirectory is a string pointing to the location of the folder where .lib file is located respective to the build.cs file of the module, so in this example FreeImageDirectory = "..//..//ThirdParty//FreeImage"

Since our DLL is third party custom lib and cannot be found among standard windows dlls The line PublicDelayLoadDLLs avoids the engine from trying to load it immediately on startup, as engine would by default look in standard windows locations to search our DLL (Which it obviously wont find)

Now since our DLL is in one of the folders in our plugin (you can use any folder , I used third party for consistency) We will load that DLL manually from the correct path as soon as the plugin module is loaded by the engine

here's how

2 In your plugin's main cpp file (like for a plugin named ABCD you'll have a ABCD.cpp)

you'll find a function named StartupModule which is called when module is loaded by the engine

all you have to do is load our DLL from the folder using **DLLHandle = FPlatformProcess::GetDllHandle(Path);*

where path indicates absolute location of our DLL file.

you can use IPluginManager::Get().FindPlugin("PluginName")->GetBaseDir(); to help in getting the path

as soon as you call **DLLHandle = FPlatformProcess::GetDllHandle(Path);* the engine will load your dll from your desired location

make sure to call FPlatformProcess::FreeDllHandle(DLLHandle); to release the DLL in the function ShutdownModule

3 In your project put the .h that came with DLL amongst the other headers , e.g I put my FreeImage.h in the private folder of my plugin source code


if everything went as expected you can just include the header in any file in the plugin and call any of the function from DLL directly as if you had the source code at your disposal, no messy function pointers

Hope this helps

more ▼

answered May 30 '16 at 05:56 PM

avatar image

Commander Shepard
772 56 80 214

avatar image ggamangom Nov 23 '16 at 01:14 AM

i want to call .dll functions but i don't know where and how to call.

avatar image Commander Shepard Nov 23 '16 at 09:55 AM

If you've done something like in my answer , then you need to just add the header files for the DLL and call the functions from there. Or if you are using a different method of calling DLL (Function pointers and stuff) then you should look at VLC plugin on the community

avatar image Wachrno Dec 03 '16 at 05:18 PM

Hi Command Shepard, I'm currently just trying to add an external library to my project. I follow the initial procedure you have here, but my ABCD.cpp file doesn't have anything written in it. Maybe it's because this is a generic project and not a plugin? :/ I can actually include the header in my code and it doesn't break, but the moment I call any function it doesn't even load the project... I thought that maybe the DLLs are not being found... It just gives an error saying that the module may not be properly set up... Do you have any idea why this might occur? Any feedback would be greatly appreciated! Thanks!

avatar image Commander Shepard Dec 03 '16 at 05:47 PM

hmm, seems like you haven't added the DLL to PublicDelayLoadDLLs or equivalent leading the engine to search the DLL as soon as your module (Game) loads , by default it'll search in system32 folder where your dll probably isn't (not that you'd want it to be there anyways).

As I understand you are trying to load DLL for a game from its main game module rather than a plugin and so you are unable to find the startup module function for your primary game module!

However its not necessary to load the DLL in that exact function you can load it anytime when you like in any function like BeginPlay or anything , just make sure to load it before you call any functions from it and unload (release the DLL Handle) when your game exits.

But, If you really want to load it on module startup (probably safer way) then read on:

in your ABCD.cpp file you might have something similar to following


Now in ABCD.h you can define a class say FWachrnoGame which extends FDefaultGameModuleImpl and override the StartupModule function there and add all your dll loading in there.

Finally in the ABCD.cpp file edit the Macro to look like following


That should do it. Sources

https://wiki.unrealengine.com/Linking_Dlls https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System

avatar image Wachrno Dec 04 '16 at 01:59 AM

woooohooooo it worked :D After I managed to understand how to set up that class! Thanks for the awesome help!

avatar image derui29 Mar 12 '19 at 02:22 AM

I have the same problem that you had. I have C++ shared library created from matlab. i have .dll .lib & .h files.I want to use it inside one of my functions. can you help me on how to set up this to work please?

avatar image bstuder Sep 25 '17 at 09:58 AM

I tried your method, but it doesn't work.

avatar image 4nof Aug 13 '18 at 02:50 PM

Tried this method, it works. commenting so I can see it in my history later - the delayed load DLL was my issue.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question