Created
March 18, 2015 03:27
-
-
Save shadowmint/a73621cdc0b0f1ba75ec to your computer and use it in GitHub Desktop.
DynamicLib.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HelloWorld.h" | |
#include "DynamicLib.h" | |
// Extern decl | |
typedef int32(*rs_trigger)(int32 value); | |
int32 DynamicLib::thing() | |
{ | |
int32 rtn = -1; | |
#if PLATFORM_WINDOWS | |
FString libpath = TEXT("libextern.dll"); | |
#elif PLATFORM_MAC | |
FString libpath = TEXT("libextern.dylib"); | |
#elif PLATFORM_LINUX | |
FString libpath = TEXT("libextern.so"); | |
#else | |
NOT IMPLEMENTED | |
#endif | |
FString filePath = FPaths::Combine(*FPaths::GamePluginsDir(), TEXT("libs/"), *libpath); | |
UE_LOG(LogTemp, Warning, TEXT("%s"), *filePath); | |
if (FPaths::FileExists(filePath)) | |
{ | |
UE_LOG(LogTemp, Warning, TEXT("File exists!")); | |
void *DLLHandle; | |
DLLHandle = FPlatformProcess::GetDllHandle(*filePath); // Retrieve the DLL. | |
if (DLLHandle != NULL) | |
{ | |
UE_LOG(LogTemp, Warning, TEXT("Valid lib.")); | |
FString procName = "rs_trigger"; | |
rs_trigger fp = NULL; | |
fp = (rs_trigger) FPlatformProcess::GetDllExport(DLLHandle, *procName); | |
if (fp != NULL) { | |
UE_LOG(LogTemp, Warning, TEXT("Valid sym.")); | |
rtn = (* fp) (100); | |
UE_LOG(LogTemp, Warning, TEXT("return: %d"), rtn); | |
return rtn; | |
} | |
else { | |
UE_LOG(LogTemp, Warning, TEXT("Invalid sym.")); | |
} | |
FPlatformProcess::FreeDllHandle(DLLHandle); | |
} | |
else { | |
UE_LOG(LogTemp, Warning, TEXT("Invalid lib.")); | |
} | |
} | |
else { | |
UE_LOG(LogTemp, Warning, TEXT("Invalid file.")); | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment