UE4插件简单正确加载插件的方法
#include "Interfaces/IPluginManager.h"
#include "HAL/FileManager.h"
bool FSURAPluginRuntimeModule::LoadHeXrDependency( )
{
// 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( "SURAPlugin" )->GetBaseDir( );
// Add on the relative location of the third party dll and load it
FString DllFolder(FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/HeXrTransceiverLib/dll")));
FPlatformProcess::AddDllDirectory(*DllFolder);
IFileManager::Get().IterateDirectoryRecursively(*DllFolder, [&](const TCHAR* Node, bool IsDir) -> bool
{
if (IsDir)
{
FPlatformProcess::AddDllDirectory(Node);
}
return true;
});
FString LibraryPath;
#if PLATFORM_WINDOWS
LibraryPath = FPaths::Combine(*DllFolder, TEXT("HeXrTransceiver.dll"));
#endif // PLATFORM_WINDOWS
HeXr_LIB_HANDLE = !LibraryPath.IsEmpty( ) ? FPlatformProcess::GetDllHandle( *LibraryPath ) : nullptr;
return HeXr_LIB_HANDLE != nullptr;
}