1

I am trying a Create a Linux C++ project using the same header and .cpp files from a Windows C++ project using Visual Studio. I am using below function to load a DLL dynamically in Windows

HINSTANCE hGetProcIDDLL = LoadLibraryA(sDllPath.c_str());
GetPluginInfoList GetInfoList = (GetPluginInfoList)GetProcAddress(hGetProcIDDLL, "GetPluginInfoList");

I think these functions hail from <windows.h>

When it comes to Linux C++ project I am not getting those functionalities. For Linux C++, what is the replacement for HINSTANCE and LoadLibraryA?

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
Hari Sankar v m
  • 163
  • 1
  • 12

1 Answers1

2

I am posting my answer here. Thanks everyone for the support

typedef CPluginInfoList(*GetPluginInfoList)(void);



#if _WINDLL
    HINSTANCE hGetProcIDDLL = LoadLibraryA(sDllPath.c_str());

#else
    void* hGetProcIDDLL = dlopen(sDllPath.c_str(), RTLD_LAZY);

#endif


#if _WINDLL
    GetPluginInfoList GetInfoList = (GetPluginInfoList)GetProcAddress(hGetProcIDDLL, "GetPluginInfoList");
#else
    GetPluginInfoList GetInfoList = (GetPluginInfoList)dlsym(hGetProcIDDLL, "GetPluginInfoList");
#endif


GetInfoList(); //Function Call
Hari Sankar v m
  • 163
  • 1
  • 12
  • Remember that there is a dlclose if you wish to fix memory leaks on program closure. – cup Jan 28 '20 at 11:08