Usage documentation
Hello!
I am not an expert on programming on Windows, so I am not too familiar with the special things that need to be taken care of when using LoadLibrary, GetProcAddr and FreeLibrary - but I do know that for all the dl*() functions.
While looking for a small abstraction above the two, I came across this library - but I actually closed the page down multiple times, but kept finding back here through Google and Github. Now, I can not really see how to properly utilize this library, as I see no docs...
What I want to do is implement native module loading for (the Wren programming language)[http://wren.io]. Therefore, I would need to do the following:
- Load a shared object (i.e.
mymodule.soormymodule.dll- or on Macmymodule.dylib) - Pick up a set of functions from it (to initialize and de-initialize)
- Unload the libraries at the end of the program's lifecycle.
The two main functions that need to be implemented are just there to properly bootstrap a module - it is supposed to return a struct with a set of functions and configuration, while the de-initialization function does the opposite, and makes sure all handles/pointers are freed properly.
So, how do I realize this quickly using this library? I only want to load one module at a time and store them within a module cache, so I can iterate through that and destruct/free them at that moment?
Kind regards, Ingwie.
You can see a working example in the unit test file: https://github.com/macmade/dlib/blob/master/Unit-Tests/Tests.cpp
Relevant part is:
#include <dlib.hpp>
extern int hv_vcpu_run( unsigned int cpu );
extern int hv_vm_foobar( uint64_t flags );
DLIB_FUNC_START( Hypervisor, int, hv_vcpu_run, unsigned int cpu )
DLIB_FUNC_RET( Hypervisor, int, hv_vcpu_run, cpu )
DLIB_FUNC_START( Hypervisor, int, hv_vm_foobar, uint64_t flags )
DLIB_FUNC_RET( Hypervisor, int, hv_vm_foobar, flags )
DLIB_FUNC_START and DLIB_FUNC_RET will generate stubs that will load the module if necessary, load the function, and call it.