Question

I'm trying to implement a plugin system, but I'm having some problems. In the plugin DLL, I have something like this code:

extern "C" __declspec(dllexport) void InitPlugin(PluginManager* pMgr)
{
    pMgr->RegisterPlugin(new MyPluginObject);
}

MyPluginObject derives from a pure virtual PluginObject class. In PluginManager::RegisterPlugin(), the pointer to the plugin object is stored for later use. I can successfully call a function in MyPluginObject from within RegisterPlugin(), but once InitPlugin returns, I get an access violation whenever I try to use the plugin object that was stored in RegisterPlugin(). How do I fix this?

Was it helpful?

Solution

Well of course I ask a question here, and figure it out myself 10 minutes later. The problem actually had nothing to do with this, instead I was using my own class to handle the loading of the DLL file. It turns out that class was accidentally deleted earlier than expected, and it unloaded the DLL with it, which invalidated everything from the DLL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top