Hey folks!
I’m trying to dive deeper into the C++ side of the engine and I’m trying to make my C++ side code, inside the game instance, use a simple DLL I’ve compiled for it. It basically has some dummy functions in a dummy class, here’s the header for it:
´´´
#ifdef WIN32
#ifdef MYLIB_EXPORT
#define MYLIB_API _declspec(dllexport)
#else
#define MYLIB_API _declspec(dllimport)
#endif
#endif
namespace MyLib
{
class MYLIB_API MyLibClass
{
public:
int Increment();
int Decrement();
int GetValue();
private:
int i = 0;
};
}
´´´
I’ve successfully compiled the DLL and used it in another application I had made, just to make sure that everything is exported correctly.
I’m trying to do the same, essentially just call some of these methods but from my cpp game instance. I’ve seen a lot of different guides, blogposts and forum posts about making plugins, creating gameplay modules, but none of that seems to fit what I’m trying to do here: to add a dll dependancy on the existing project module.
Is what I’m trying to do even possible, or should I go through the seemingly unnecessary chore of making a plugin / gameplay module out of these few method calls?
If not, how would I do it? I’ve placed all the MyLib files in a folder inside my Source/ProjectName directory and I’ve been trying to modify the ProjectName.Build.cs file to include the header, lib and dll by copying the contents of the Build files of the Engine/Source/ThirdParty files:
´´´
…
public class ProjectName: ModuleRules
{
public ProjectName(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore"
});
PrivateDependencyModuleNames.AddRange(
new string[]
{
});
PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "MyLib", "MyLib.dll"));
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "MyLib"));
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "MyLib", "MyLib.lib"));
}
}
´´´
With all of this, the .sln does compile and launches the editor, but the ProjectName module fails to load. I’ve tried copying the .dll to the Binaries but that didn’t really do anything.
I’ve read that since I’m on windows, I need to manually import the dll and manually bind the methods or something?.. If so, how would I do that, I’m not finding any comprehensive resources on that topic.
Thank you for your help!