一般都是因为你的dll还有其他依赖dll没找到引起的
注意看?GetLastError=126就是找不到依赖dll
下面是正常动态加载dll的代码
//获取ChessDll插件路径
FString BaseDir = IPluginManager::Get().FindPlugin("ChessDll")->GetBaseDir();
//拼接路径
FString LibraryPath;
LibraryPath = FPaths::Combine(*BaseDir,TEXT("Binaries/ThirdParty/ChessLibrary/Win64/untitled.dll"));
//把这个路径加入搜索,主要可以搜到依赖dll
FPlatformProcess::PushDllDirectory(*(FPaths::ProjectDir() / TEXT("Plugins/ChessDll/Binaries/ThirdParty/ChessLibrary/Win64/")));
//加载dll
ChessLibraryHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr;
if (ChessLibraryHandle)
{
}
else
{
//弹窗报错
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ThirdPartyLibraryError", "Failed to load example ChessDll library"));
}
#include "Modules/ModuleManager.h"
另外如果是c++的dll注意函数命名,也许你的add叫做_Z3addii
调用的话就如下图
?感觉最难的还是函数指针,有头文件最好加上头文件,能省很大功夫
|