方式一// dll内的函数引用声明
typedef void(*_Initial)(
char* thisPCID,
char* thisConnectioninfo,
char* thisExpVersion,
char* thisSessionlD
);
void *DLLHandle;
_Initial DLL_Initial;
//加载
bool UDLLTest::DLL_Init() {
FString filePath = FPaths::Combine(*FPaths::GamePluginsDir(), TEXT("DLL/"), TEXT("test.dll"));
if (FPaths::FileExists(filePath)) {
UE_LOG(LogTemp, Log, TEXT("%s"), *filePath);
// 绑定dll
DLLHandle = FPlatformProcess::GetDllHandle(*filePath);
if (DLLHandle != NULL) {
DLL_Initial=NULL;
//绑定函数
FString procName = "Initial"; // dll里的函数名
DLL_Initial = (_Initial)FPlatformProcess::GetDllExport(DLLHandle, *procName);
if(DLL_Initial != NULL){
UE_LOG(LogTemp, Log, TEXT("DLL_Initial import succ"));
return true;
}
}
}
return false;
}
//释放
void UDLLTest::DLL_Free() {
if(DLLHandle !=NULL){
DLL_Initial = NULL;
FPlatformProcess::FreeDllHandle(DLLHandle );
DLLHandle = NULL;
}
}