'How does UnrealEngine thirdparty plugin working without GetProcAddress?
I'm learning UnrealEngine from begining, and I found a miraculous phenomenon: the Unreal thirdparty plugin load a thirdparty dll file with "LoadLibrary" function and invoke the function in dll file without GetProcAddress!
here is the plugin code:
void FMyPluginModule::StartupModule()
{
// 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("MyPlugin")->GetBaseDir();
// Add on the relative location of the third party dll and load it
FString LibraryPath;
#if PLATFORM_WINDOWS
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/MyPluginLibrary/Win64/ExampleLibrary.dll"));
#elif PLATFORM_MAC
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Source/ThirdParty/MyPluginLibrary/Mac/Release/libExampleLibrary.dylib"));
#elif PLATFORM_LINUX
LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/MyPluginLibrary/Linux/x86_64-unknown-linux-gnu/libExampleLibrary.so"));
#endif // PLATFORM_WINDOWS
//the GetDllHandle function load the dll file with LoadLibrary API
ExampleLibraryHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr;
if (ExampleLibraryHandle)
{
// Call the test function in the third party library that opens a message box
// invoke ExampleLibraryFunction exported in dll file without GetProcAddress!!!!
ExampleLibraryFunction();
}
else
{
FMessageDialog::Open(EAppMsgType::Ok, LOCTEXT("ThirdPartyLibraryError", "Failed to load example third party library"));
}
}
After load the dll dynamicly with GetDllHandle function, the plugin code invoke ExampleLibraryFunction just like implicit link, how's that working....
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
