When to use RuntimeDependency vs PublicDelayLoadDLLs?

After sifting through hundreds of forms about linking and using DLLs in UE4, I still have not found a clear definition as to when to use which functions to link DLLs to a project. I am working on a plugin to connect our game project to our MySQL database. I am using MySQLCppConnector libraries and DLLs from Oracle. I had successfully build our first plugin to perform these actions, but I was not able to use them anywhere else besides plugins. I had included the proper API to the plugin to expose the module to the engine without any luck, and would receive build errors whenever I would try to include any header files from the plugin into the actual game project.
After giving up on the first revision of the plugin, I decided to start from scratch. I figured the errors are probably being generated due to improper linking of the MySQL dll and lib files. My first implementation used PublicIncludePaths.Add(IncludesPath, “cppconn”), PublicDelayLoadDLLs(DLLName) where DLLName was the absolute path to the DLL file, and PublicAdditionalLibraries.Add(LibraryName) where LibraryName was the absolute path to the .lib file for the DLL. Again, I would have no build errors until I tried to include the Class headers of the plugin in the module via C++. It works fine in strictly blueprints.
So, after looking at how another developer laid out his code for a VLC plugin that uses DLLs, I noticed that he is using RuntimeDependencies.Add(new RuntimeDependency(AbsolutePathToDll) but doesn’t use the PublicIncludePaths.Add() or PublicDelayLoadDLLs() functions. I’ve also noticed that some will manually import/export the dll functions, defining each function that they need from the DLL file. I didn’t think that was necessary when working with DLLs, at least not on past projects I’ve worked with.
What does each function actually do and when should I use them to properly link a DLL file with the non static .lib and the proper includes directories containing the DLLs functions? I’ve had a pretty hard time figuring out how to use DLLs in the engine and have finally come to the point of posting for help.
Thanks in advanced for any help or advice you can give. I think I’ve about exhausted Google’s search engine on this topic. :slight_smile: haha

1 Like

I forgot to clarify, I wouldn’t receive build errors on my first revision, but after trying to launch the editor, it would stop at apx 75% notifying me that the module was not setup properly / not loaded correctly. The editor would load up fine if I didn’t include any class header files from the plugin into the game project. And everything would work great on the blueprints end, but that cripples me on the coding side.

Since you were the only responder, thank you. Yeah, the tutorials are pretty scarce when it comes to the core functionality of Unreal Engine 4.

So the big issue with the “MySQL-Connector-Plugin” you posted, is that it is only for Maria-DB. While that is an extension of MySQL, it won’t work directly with a MySQL database. The other thing I wasn’t a huge fan of the plugin, is that you have to manually edit the plugin’s build file to match the name of your project. I ended up building mine so that it would auto-detect your project and set itself up by dropping it straight into your project’s plugins folder. That was the whole reason I ended up building our own MySQL plugin.

So what I did figure out after finishing the plugin, was that if you drop the dll into your project’s binaries folder, the engine will automatically load any .dll files it finds in there. (It makes sense, since all of the engine’s dlls reside there.) So I built my plugin to add the MySQLConnector.dll file in the Binaries folder automatically. Everything seemed to work from there.

I think a lot just had to do with my lack of experience in UE4. I’ve worked with DLLs in my own c++ projects, but this was a first time for UE4.

Thank you Jin_VE for your help.

Hi!

I had a lot of trouble linking to a DLL as well. The tutorials are insufficient as far as I can tell. Fortunately, a recent update (4.14 IIRC) revamped the plugin system and now you can have the editor generate a plugin (framework) for you. Go into Edit->Plugins and there’s a “New plugin” button. One of the options is to create a “Third Party Library” plugin. That’s the one you want. Replace the default lib/DLL with the one(s) you want to use.

It may take some finagling. It did for me but I was able to get UE4 to load and use my DLL. Good luck!

Also, I checked to see if there is an existing MySQL plugin and I found this. Maybe it can save you the trouble. MySQL Connector UE4 Plugin is available for all now - C++ - Epic Developer Community Forums