Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
class CDllHelper

Class to help with load of shared library functions
You can add them as parent to your class and to help with load of shared library functions. More...

Classes

class  kodi::tools::CDllHelper
 

Macros

#define REGISTER_DLL_SYMBOL(functionPtr)
 Macro to translate the given pointer value name of functions to requested function name.
 

Functions

 kodi::tools::CDllHelper::CDllHelper ()=default
 Class constructor.
 
virtual kodi::tools::CDllHelper::~CDllHelper ()
 Class destructor.
 
bool kodi::tools::CDllHelper::LoadDll (std::string path)
 Function to load requested library.
 
template<typename T >
bool kodi::tools::CDllHelper::RegisterSymbol (T &functionPtr, const char *strFunctionPtr)
 Function to register requested library symbol.
 

Detailed Description

Class to help with load of shared library functions
You can add them as parent to your class and to help with load of shared library functions.

Note
To use on Windows must you also include dlfcn-win32 on your addon!

Furthermore, this allows the use of Android where the required library is copied to an EXE useable folder.

Example:

...
class CMyInstance : public kodi::addon::CInstanceAudioDecoder,
{
public:
CMyInstance(KODI_HANDLE instance, const std::string& kodiVersion);
bool Start();
...
// The pointers for on shared library exported functions
int (*Init)();
void (*Cleanup)();
int (*GetLength)();
};
CMyInstance::CMyInstance(KODI_HANDLE instance, const std::string& kodiVersion)
: CInstanceAudioDecoder(instance, kodiVersion)
{
}
bool CMyInstance::Start()
{
std::string lib = kodi::GetAddonPath("myLib.so");
if (!LoadDll(lib)) return false;
if (!REGISTER_DLL_SYMBOL(Init)) return false;
if (!REGISTER_DLL_SYMBOL(Cleanup)) return false;
if (!REGISTER_DLL_SYMBOL(GetLength)) return false;
Init();
return true;
}
...
void * KODI_HANDLE
Standard undefined pointer handle.
Definition addon_base.h:291
Definition addons/kodi-dev-kit/include/kodi/addon-instance/AudioDecoder.h:431
Definition DllHelper.h:93
#define REGISTER_DLL_SYMBOL(functionPtr)
Macro to translate the given pointer value name of functions to requested function name.
Definition DllHelper.h:27
unsigned int(ATTR_APIENTRYP PFN_KODI_ADDON_VISUALIZATION_GET_PRESETS_V1)(const KODI_ADDON_VISUALIZATION_HDL hdl)
Definition kodi-dev-kit/include/kodi/c-api/addon-instance/Visualization.h:73
typedef void(ATTR_APIENTRYP PFN_KODI_ADDON_SCREENSAVER_STOP_V1)(const KODI_ADDON_SCREENSAVER_HDL hdl)
Definition addon_base.h:268

Macro Definition Documentation

◆ REGISTER_DLL_SYMBOL

#define REGISTER_DLL_SYMBOL ( functionPtr)
Value:
kodi::tools::CDllHelper::RegisterSymbol(functionPtr, #functionPtr)
bool RegisterSymbol(T &functionPtr, const char *strFunctionPtr)
Function to register requested library symbol.
Definition DllHelper.h:190

Macro to translate the given pointer value name of functions to requested function name.

Note
This should always be used and does the work of kodi::tools::CDllHelper::RegisterSymbol().

Function Documentation

◆ CDllHelper()

kodi::tools::CDllHelper::CDllHelper ( )
default

Class constructor.

◆ LoadDll()

bool kodi::tools::CDllHelper::LoadDll ( std::string path)
inline

Function to load requested library.

Parameters
[in]pathThe path with filename of shared library to load
Returns
true if load was successful done

◆ RegisterSymbol()

template<typename T >
bool kodi::tools::CDllHelper::RegisterSymbol ( T & functionPtr,
const char * strFunctionPtr )
inline

Function to register requested library symbol.

Warning
This function should not be used, use instead the macro REGISTER_DLL_SYMBOL to register the symbol pointer.

Use this always via Macro, e.g.:

return false;

◆ ~CDllHelper()

virtual kodi::tools::CDllHelper::~CDllHelper ( )
inlinevirtual

Class destructor.