// 版权所有 Epic Games, Inc. 保留所有权利。

#include 'mysqlcont.h' #include 'Misc/MessageDialog.h' #include 'Modules/ModuleManager.h' #include 'Interfaces/IPluginManager.h' #include 'Misc/Paths.h' #include 'HAL/PlatformProcess.h' #include 'mysqlcontLibrary/ExampleLibrary.h'

#define LOCTEXT_NAMESPACE 'FmysqlcontModule'

void FmysqlcontModule::StartupModule() { // 当模块加载入内存后,此代码将执行;确切的时间由.uplugin文件中的指定

// 获取此插件的基础目录
FString BaseDir = IPluginManager::Get().FindPlugin('mysqlcont')->GetBaseDir();

// 添加第三方dll的相对路径并加载它
FString LibraryPath;

#if PLATFORM_WINDOWS LibraryPath = FPaths::Combine(*BaseDir, TEXT('Binaries/ThirdParty/mysqlcontLibrary/Win64/ExampleLibrary.dll')); #elif PLATFORM_MAC LibraryPath = FPaths::Combine(*BaseDir, TEXT('Source/ThirdParty/mysqlcontLibrary/Mac/Release/libExampleLibrary.dylib')); #elif PLATFORM_LINUX LibraryPath = FPaths::Combine(*BaseDir, TEXT('Binaries/ThirdParty/mysqlcontLibrary/Linux/x86_64-unknown-linux-gnu/libExampleLibrary.so')); #endif // PLATFORM_WINDOWS

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

if (ExampleLibraryHandle)
{
	// 调用第三方库中的测试函数,打开一个消息框
	ExampleLibraryFunction();
}
else
{
	FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT('ThirdPartyLibraryError', '无法加载示例第三方库'));
}

}

void FmysqlcontModule::ShutdownModule() { // 在卸载模块之前,此函数可能会在关闭时被调用以清理模块。对于支持动态重新加载的模块, // 我们在卸载模块之前调用此函数。

// 释放dll句柄
FPlatformProcess::FreeDllHandle(ExampleLibraryHandle);
ExampleLibraryHandle = nullptr;

}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FmysqlcontModule, mysqlcont)

Unreal Engine插件开发:加载第三方库

原文地址: https://www.cveoy.top/t/topic/bxn6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录