   Dynamic object and Dynamic DLL ...
  Hello all,I have a question dealing with this situation I'm trying to pull off. What I'm wanting to do is have a class interface that sits between my exe, and dll. I call the DLL from the EXE dynamically and the DLL creates a new instance of the class and passes it back. The EXE side uses this new class variable throughout the EXE, just simply referencing it's calls which is really happening on the DLL side of things once called. At the apps end, the EXE can simply delete the variable it has referenced as the class from memory.I have some code here at the bottom just simply showing the basic idea of what I'm doing, it seems to create and reference the variable somewhat correctly on the EXE side, although it seems the functions on the DLL side are not getting called at all. Also, upon deleting the variable I have on my EXE side, created from the DLL, it of course breaks with an error (HEAP memory error).You can sorta see below how my layout is working. I have a class on the EXE side that is basically manager for the DLL, this is where its calling the CreateInterface call to the DLL side and passing back the reference to the object that called it. The other class is has created a reference to this DLL manager class, and also has a MyInterface variable that is keeps and calls the DLL Manager class to do its thing to the DLL and pass back the reference to the new object.Any help or suggestions I would greatly appreciate. I have other implementations, though not as neat and clean as this one, that do work and I can use. I just wanted to make a neater layout than the previous ones I had been using and exploring. I know I can simply make the DLL Static and just do as I please, but the whole concept here is to keep the DLL dynamic and allow for a simple Interface Class to be the connector between the two.Here is the current code I have as a Test:///////////////////////////// Interface Class// Shared between EXE and DLL///////////////////////////class MyInterface{public://Base Creation and destroy functionsvirtual HRESULTInitialize()=0;virtual HRESULTDestroy()=0;};///////////////////////////// My Class// DLL Side Implementation// of Interface Class///////////////////////////#include "myinterface.h"class MyClass : public MyInterface{public:MyClass(){};~MyClass(){};HRESULTInitialize() { return S_OK;};HRESULTDestroy(){ return S_OK;};};///////////////////////////// DLL main CPP//////////////////////////#include "myclass.h"#define DLLEXPORTextern "C" _declspec(dllexport)DLLEXPORT void* CreateMyClass(){return static_cast< void* > (new MyClass());}///////////////////////////// EXE main CPP//////////////////////////#include "myinterface.h"MyInterface* SomeClass::DoCreate(){    //Attempt create MyInterface across to DLL.    typedef void* (*LPFNDLLCALL)();    LPFNDLLCALLlpfnDllCall;    lpfnDllCall = (LPFNDLLCALL)GetProcAddress(_hModDLL,   "CreateMyClass");   if (!lpfnDllCall)   { return NULL;   }    return (MyInterface*)lpfnDllCall();}void SomeOtherClass::SomeOtherFunction(){   SomeClass* _someClass = new SomeClass();   MyInterface* _myInterface = _someClass->DoCreate();   //code continues ...   delete _myInterface;}
  I wrote a great deal about DLLs a bit back in my journal. It should answer the majority of your questions...   ;Quote:Original post by WashuI wrote a great deal about DLLs a bit back in my journal. It should answer the majority of your questions...Thank you so much Washu !Your articles did the trick ... again thanks for the pointers.   