When you have a base class in your main executable and subclasses (say, plugins) defined in DLLs, what happens when you want to get a plugin?
I am looking for an article/answer that'd clarify what happens when you
plugin*
(it has virtual functions)I am thinking about the vtable and other C++ issues. For instance, if you unload the DLL stil having some plugins running... The "code" will be gone?
Since you are talking about plugins, you must be doing something like LoadLibrary
. Assuming Windows:
LoadLibrary
followed by GetProcAddress
. The DLL is loaded into the process address space and you have the pointer to the function exposed.plugin*
(it has virtual functions). You would cast a the return value from GetProcAddress
to the function pointer type, and call it. Everything should work as normal.delete
can be dangerous, as the DLL may have a separate memory manager (depending on what runtime you use).FreeLibrary
, and the code is gone. The pointers you previously get from GetProcAddress
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.