![]() |
PIP 5.5.3
Platform-Independent Primitives
|
Run-time library. More...
#include <pilibrary.h>
Public Member Functions | |
| PILibrary (const PIString &path_=PIString()) | |
| Constructs PILibrary and load if "path_" not empty. | |
| ~PILibrary () | |
| Destroy PILibrary, unload if library was loaded. | |
| bool | load (const PIString &path_) |
| Load library with relative or absolute path "path_". | |
| bool | load () |
| Load library with path() path. | |
| void | unload () |
| Unload library if it was loaded. | |
| void * | resolve (const char *symbol) |
| Obtain exported library method with name "symbol". More... | |
| bool | isLoaded () const |
| Returns if library successfully loaded. | |
| PIString | path () const |
| Returns library path. | |
| PIString | lastError () const |
| Returns last occured error in human-readable format. | |
Run-time library.
PILibrary allow you dynamically load external library and use some methods from it. PILibrary instance contains library pointer and unload library on destructor, so recommended to use it with new creation.
Main method of PILibrary is resolve(const char *), which returns void* pointer to requested method. One should test it to nullptr and convert it in pointer to the required method.
In case of C++ libraries it`s very important to use C-linkage of exported methods! You may also need to mark methods for export, e.g. __declspec(dllexport). You can include <piplugin.h> and use PIP_PLUGIN_EXPORT to mark exports with PIP.
Library:
Program:
| void * PILibrary::resolve | ( | const char * | symbol | ) |
Obtain exported library method with name "symbol".
Returns exported method with name "symbol" from loaded library. Method have to use C-linkage and marked to export, according to compiler specification.
C-linkage doesn`t provide information about return type and arguments, so you should manually convert obtained pointer to required method format before call.
void* pointer to method or
nullptr if method doesn`t exists or library not loaded