Hi
I'm making my first application with plugins. I went through a lot of articles about this and only got more confused, but I came up with my own idea about how to do this. And it SEEMS to work.
While working on my program, I want to ask somebody more experienced than me whether my design is really ok, or if there are memory leaks or something that I don't see... here it goes:
The application consists of a "core" (the exe) and the plugins (DLLs). In the core, I define an abstract class
class CBase
{
private:
CBase();
public:
virtual ~CBase() = 0;
virtual void Method() = 0;
};
In each DLL, I define a CBase's derived class CDerived and a function
CBase* GetInstance()
{
return (CBase*) new CDerived;
}
which is the only thing exported from the dll.
The idea is that the exe will work with objects of type CBase, but those objects will really be instances of the derived classes. The exe will load each plugin and call GetInstance() to obtain an object pointer.
I have already written the described program and it seems to work, but is it really ok? I mean for example when I do
CBase base = lpfnGetInstance();
delete base;
will the object get deallocated properly? I have read somewhere that the EXE and the DLL have different memory managers, so I don't know if it's ok to get an object pointer from the dll and call delete on it in the exe....? I repeat that this compiles correctly and does not produce any run-time errors, also Visual Leak Detector (from CodeProject) says that there are no memory leaks...
thanks in advance for your opinions