Failed to load a module that has link with third party dll.

Hi, I’m trying to make a runtime skp importer with [this SketchUp C API Document][1] and the SDK files.

I created a plugin using third-party library template and


1. Copied .dll and .lib into the directory where example .dll and .lib exists.


2. Copied headers into the corresponding directory too.

3. Added paths in the .build.cs file.

using System.IO;
using UnrealBuildTool;

public class SkpImporterLibrary : ModuleRules
{
	public SkpImporterLibrary(ReadOnlyTargetRules Target) : base(Target)
	{
		Type = ModuleType.External;

		if (Target.Platform == UnrealTargetPlatform.Win64)
		{
            PublicIncludePaths.Add("$(PluginDir)/Source/ThirdParty/SkpImporterLibrary");

            // Add the import library
            // List of additional libraries (names of the .lib files including extension) - typically used for External (third party) modules
            PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "x64", "Release", "ExampleLibrary.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "x64", "Release", "sketchup.lib"));
            PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "x64", "Release", "SketchUpAPI.lib"));


            // Delay-load the DLL, so we can load it from the right place first
            PublicDelayLoadDLLs.Add("ExampleLibrary.dll");
            PublicDelayLoadDLLs.Add("SketchUpAPI.dll");
            PublicDelayLoadDLLs.Add("SketchUpCommonPreferences.dll");

            // Ensure that the DLL is staged along with the executable
            RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/SkpImporterLibrary/Win64/ExampleLibrary.dll");
            RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/SkpImporterLibrary/Win64/SketchUpAPI.dll");
            RuntimeDependencies.Add("$(PluginDir)/Binaries/ThirdParty/SkpImporterLibrary/Win64/SketchUpCommonPreferences.dll");

        }
        else if (Target.Platform == UnrealTargetPlatform.Mac)
        {
            PublicDelayLoadDLLs.Add(Path.Combine(ModuleDirectory, "Mac", "Release", "libExampleLibrary.dylib"));
            RuntimeDependencies.Add("$(PluginDir)/Source/ThirdParty/SkpImporterLibrary/Mac/Release/libExampleLibrary.dylib");
        }
	}
}

4. Modified the module’s main .cpp file.

#include "SkpImporter.h"
#include "Core.h"
#include "Modules/ModuleManager.h"
#include "Interfaces/IPluginManager.h"
#include "SkpImporterLibrary/ExampleLibrary.h"
#include "SkpImporterLibrary/SketchUpAPI/initialize.h"

#define LOCTEXT_NAMESPACE "FSkpImporterModule"

void FSkpImporterModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

	// Get the base directory of this plugin
	FString BaseDir = IPluginManager::Get().FindPlugin("SkpImporter")->GetBaseDir();

	// Add on the relative location of the third party dll and load it
	FString LibraryPath;
#if PLATFORM_WINDOWS
	LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/SkpImporterLibrary/Win64/SketchUpAPI.dll"));
#elif PLATFORM_MAC
    LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/SkpImporterLibrary/Mac/Release/libExampleLibrary.dylib"));
#endif // PLATFORM_WINDOWS

	ExampleLibraryHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr;

	if (ExampleLibraryHandle)
	{
		// Call the test function in the third party library that opens a message box
		SUInitialize();
	}
	else
	{
		FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ThirdPartyLibraryError", "Failed to load example third party library"));
	}
}

void FSkpImporterModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.

	// Free the dll handle
	FPlatformProcess::FreeDllHandle(ExampleLibraryHandle);
	ExampleLibraryHandle = nullptr;
}

#undef LOCTEXT_NAMESPACE
	
IMPLEMENT_MODULE(FSkpImporterModule, SkpImporter)

Building solution is done. But when I execute the project, a message pops up:

Is there anything I am missing? Any help would be very appreciated. Thanks for reading…

One thing that is definition an issue is that you shouldn’t have to load both the lib and dll. The lib is a static library which gets compiled into the library. The latter is a dynamic library which doesn’t get loaded in at compile time, but loads separately at run time. You should only need one or the other.

With that said, I’m having the same issue with just trying to load a plugin with a compiled lib file. Were you able to figure this out?

Eh what I said is not always true. Apparently some libraries will provide static libraries that then just load the dynamic library. Perhaps this is what is happening with me

Thanks for the reply. I don’t know much how handle libraries. So I just copied and pasted all the files into the folder. Fortunately, I had the module loaded successfully after many trials and errors. And thanks to your comment, I noticed that I used only two dlls and can consider remove libs from the folder.

But I have question about the files size. Because the SketchUpAPI.dll is 9,119KB and the lib file that has same name(SketchUpAPI.lib) is just 249KB. What makes the difference? Do they have same code inside them? Is it fine to remove the lib files? I need to find the answers.

Anyway, thank you for your comment.

Unfortunately I’m not sure about your specific libraries. It’s possible that SketchUpAPI.lib just provides some bare bone logic to load in the meatier SketchUpAPI.dll at a later point. Traditionally speaking, .dll files are larger than .lib files because they include more metadata. However that is a very sizeable difference which makes me think that you may need both of them.

Alright, I got mine to load. I can confirm that’s what’s happening. the .lib contains the metadata so that you can delay the load the .dll which has all the actual code. You need both :slight_smile:

oops. Didn’t mean to hijack this thread. My other comments deleted. My concern is related to this posting, yet a bit different.

I started a new conversation on third party plug ins, over here instead.