How to load (own) DLL in Runtime?

Greetings,
for my current project I need to to bind some dlls for the game (Runtime). I tested it in the Editor (PIE) and everthing worked fine but after I packaged the game I get the error, that my dlls couldn’t be loaded. I find out that the Path from my plugin doesn’t point to a “valid” address.

How I get the plugin address

 IPluginManager::Get().FindPlugin("ThatCoolPlugin")->GetBaseDir();
 DllNameDir = FPaths::Combine(*PluginDir, TEXT("Binaries/Name/Win64/dllName.dll"));

My question is how should I bind the dll so the packaged game can find the dll?
Currently the Binaries are stored in a “Binaries” folder in the “ThatCoolPlugin” folder, which is in the plugin folder.

How I load the Dlls

DllNameHandle = !DllNameDir .IsEmpty() ? FPlatformProcess::GetDllHandle(*DllNameDir ) : nullptr;

Some details:
I used common ways to load unload the dll. My plugin settings (Rules) can be compared with the Third Party Library Example plugin. The major differents between these settings is, that my setting type is Runtime not development.

Edit:
What I want to know is, what do I need to do if an plugin is from the type “Runtime”, while I load dlls?
I saw that in the packaged Game has a Engine/Binaries/ThirdParty folder. But their are dlls such PhysX. VR, et cetera. Is it possible to write a Plugin (or something else) which store his binaries in the same folder? or in another folder where the engine can find it?

Any advice? This is a serious issue in the current porject I’m working on.

My understanding is it isn’t really supported yet due to security concerns. Having said that have a dig around the UT forums because I think others have been pursuing this avenue.

Can you refactor to get the dll logic into blueprints? This should be currently supported and is the approach I’m following but it’s also a better fit for my particular distribution model.

what do you mean with refactor? To implment the dll logic into blueprint? I have access to the source code from the dll but I don’t have the permission to modify it.

Can you provide an actual example of what you are trying to do?

What I’m trying can be achieved by making the “ThirdParty Plugin example” runtime capable. Just create a new “ThirdParty Plugin” then change the Type to Runtime in the .uplugin file. But after that the engine cannot finde the dll direction in the packaged game

I meant more like “final result in game”. Why a dll is required in the first place (why you can’t ship exe logic in a single exe and extend it in blueprints).

Honestly you’re outside my experience here but pathing in DLC is a little tricky. If you are packaging the dll within a pak file I’ve found that:

  • Paths within the pak file are relative to its mount path (use the -List UnrealPak option to see where they are).
  • Paths within the pak file are the relative path between the point the pak file was created at and the files that were put in it. If you create a pak file at c:\afolder\mypakfile.pak then c:\afolder\bfolder\c.file will have the path bfolder\c.file
  • Mount point for a pak file is set within the FPakPlatformFile::Mount function (i.e. final path is combination of the path provided to mount AND the path within the packfile.
  • There is a second mount point, for unreal content (mounting uassets into the unreal asset browsing system). This is setup using FPackageName::RegisterMountPoint
  • For this second mount point new calls with and old mountpoint will replace previous calls, so you can’t mount two things to /DLC/ you’ll need /DLC1/ and /DLC2/

Really not sure if any of this helps you! Can you see the dll in the final packaged game directory structure?

Again, you’re outside my experence but mounting a dll sounds likely platform specific and something that has seemed not supported in the few places I’ve come across it, but I look forward to someone chiming in here and detailing how its going to work (especially in a nice wrapped up portable manner!).

Good luck :slight_smile:

What Pak has anything to do with this? All dll should be outside of any achieve to be usable

Did you tried this set up? if you can you should link dll staticly to UE4 module.

I didn’t try it because I want to link dynamic not static. But I don’t see any way to achive this. I will mark your answer as best because at least it solve the problem. I hope this will be possible in the future :slight_smile:
thanks for the helpful answer :slight_smile:

Hi , did you ever work out a solution for this? Sorry that everyone else posting gave you such a crappy answer :frowning: