Third party library plugin : how can I rebuild library while unreal engine block the dll

Hello,
Due to my company needs, I am to see if it’s easy to work with third party dlls (we have much of them and would like to plug them in the engine).
So I try the third party library plugin template (with the ExampleLibrary printing “Hello world” at plugin load).

My problem is I’m not able to get my change in example library (printing “hellow world 2” instead of “Hello world”) to be reflected in the editor :

  • Changing the exampleLibrary.cpp from Plugin project and rebuilding plugin project (from vs or ue4 editor) seems to do nothing about the ExampleLibrary dll
  • Changing ExampleLibrary.cpp from ExampleLibrary sln (in another vs), and rebuilding it (in the other vs) give me an error at postbuild when the dll is copied into project thirdparty folder :

error MSB3073: command "copy
“D:\MRC\Documents\Unreal
Projects\PluginProject\Plugins\MyPlugin\Source\ThirdParty\MyPluginLibrary\x64\Release\ExampleLibrary.dll”
"D:\MRC\Documents\Unreal
Projects\PluginProject\Plugins\MyPlugin\Source\ThirdParty\MyPluginLibrary......\Binaries\ThirdParty\MyPluginLibrary\Win64"
stop with error code 1.

I guess ExampleLibrary.dll is always loaded by ue4 editor (an so , is write protected)

So my question is :
what is the best way to get external library change reflected in editor ?

I hope it is not mandatory to close ue4 in order to build external library

I found something interesting (I don’t know why unreal does not already do that in the template) :

After FPlatformProcess::FreeDllHandle(ExampleLibraryHandle); (in FMyPluginModule::ShutdownModule) add this :

__FUnloadDelayLoadedDLL2(“ExampleLibrary.dll”);

And then the third party library will really be unloaded from memory, and can be replaced when the post build of the third party library occurs.

Headers needed :

<windows.h>

<delayimp.h>

reference for delay unload on windows :

Best solution I came to to manage third party loading and unloading (including dependencies) :

#include "MyPlugin.h"
#include "Core.h"
#include "ModuleManager.h"
#include "IPluginManager.h"
#include "ThirdPartyLoader/Public/ThirdPartyLoader.h"

#include <windows.h>  

#define LOCTEXT_NAMESPACE "FMyPluginModule"
int firstLoad = true;

void FMyPluginModule::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("MyPlugin")->GetBaseDir();

	// Add on the relative location of the third party dll and load it
	FString LibraryPath;
	FString LibraryDir;

	LibraryDir = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/MyPluginLibrary/Win64/"));
	LibraryPath = FPaths::Combine(*LibraryDir, TEXT("ThirdPartyLoader.dll"));

	SetDllDirectory(*LibraryDir);
	if(!firstLoad) ExampleLibraryHandle = LoadLibrary(*LibraryPath);

	ThirdPartyLoader::Run();

	if (firstLoad)
	{
		firstLoad = false;
		ExampleLibraryHandle = GetModuleHandle(*LibraryPath);
	}
	
	SetDllDirectory(nullptr);
}

void FMyPluginModule::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
	FreeLibrary((HMODULE)ExampleLibraryHandle);
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FMyPluginModule, MyPlugin)

This only works for windows.
Dlls of third party library and all its depencies must be copied into the plugin third party binaries directory.