Should i call FPlatformProcess::PushDllDirectory & FPlatformProcess::PushDllDirectory?

new to C++, so i apologize if this is a simple question.

should i call PushDllDirectory & PopDllDirectory everytime i want to call a specific function from a dll?

or is calling it once in my plugin’s StartupModule function enough to keep the functions callable throughout my code and i should pass it to my other classes, is that possible?

also should i call FreeDllHandle in the ShutdownModule or everytime i’m done with function i called?

thanks for the help.

So it sounds like you’re trying to link a thirdparty (self made?) dll and call that code. Could you provide a bit more context, specifically whether I’m assuming correctly, and on what your intentions are?

hey. yes I have a third party dll that’s already linked. I can call the functions with an .hpp that has been provided.

just wondering if calling FPlatformProcess::PushDllDirectory, FPlatformProcess::GetDllHandle & FPlatformProcess::PopDllDirectory once on StartupModule is enough to keep the dll (sorry if I’m saying this next part wrong) open in memory, so I can use those functions freely throughout the .cpp I’m making for ue4 until I call FPlatformProcess::FreeDllHandle on ShutdownModule.

or should I use Push, GetDllHandle & Pop everytime I want to call a function from this third party dll.

sorry if I’m not explaining this correctly.

thanks for the response but i’m already past this part. i can call dll functions.
my build.cs is fine.

wondering about PushDllDirectory, PopDllDirectory and if it stays in memory until FreeDllHandle is called.

AFAIK if you link the dll in your .Build.cs file, you do so through

PublicAdditionalLibraries.Add("path_to_lib_file");
PublicDelayLoadDLLs.Add("path_to_dll_file");

Getting a path to Source/Game/Game.Build.cs:

using System.io;

string ProjectPath = Path.Combine(ModuleDirectory, 
       "../../", //  here is you .uproject
);

So then you can do:

PublicAdditionalLibraries.Add(Path.Combine(ProjectPath, "something.lib");
PublicDelayLoadDLLs.Add(Path.Combine(ProjectPath, "something.dll");

Doing this would mean you don’t have to do anything special to load you dll, ue4 will do that for you. Nevertheless this may not fit your use case?

My experience in the past was the following:

  1. Add dll to PublicDelayLoadDLLs();
  2. Engine takes care of loading DLL

Testing that today while linking OpenCV however did not give me the same results. Regression in 4.12 maybe?

Also because of my previous experience with linking, I’m saying you shouldn’t need to call the functions you describe.