Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top