Since you are talking about plugins, you must be doing something like LoadLibrary
. Assuming Windows:
- Load a library. You would normally call
LoadLibrary
followed byGetProcAddress
. The DLL is loaded into the process address space and you have the pointer to the function exposed. - Call a DLL's function that returns a
plugin*
(it has virtual functions). You would cast a the return value fromGetProcAddress
to the function pointer type, and call it. Everything should work as normal. - Use that plugin in your main executable's code. There is nothing special.
- Delete the plugin. I assume you use a function in the DLL to do so, and it should be fine. Directly calling
delete
can be dangerous, as the DLL may have a separate memory manager (depending on what runtime you use). - Unload the DLL. You call
FreeLibrary
, and the code is gone. The pointers you previously get fromGetProcAddress
become invalid.
I am not aware specific vtable issues. If you unload the DLL while the code is still running, I would assume the program will crash at this point, as the code address space becomes invalid.