exporting class problem

I am trying to create a class that I can utilise from both VB and VC++...

I am exporting a class from a DLL using __declspec (dllexport) in the class definition.

class __declspec(dllexport) CMyClass : public CCmdTarget

and I can access this class from VB and from VC++ applications OK, except that if I try to delete an instance of the class from VC++ whilst in debug mode it breaks in NTDLL? If I don't delete the instance and let it go out of scope instead there are no problems that I can see.

app code

CMyClass *pClass = new CMyClass();
pClass->m_myProperty = 99;
delete pClass;                          // problem here

the class destructor

CMyClass::~CMyClass()
{
// To terminate the application when all objects created with
// with OLE automation, the destructor calls AfxOleUnlockApp.
      
AfxOleUnlockApp();
}




mark_sAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Gus012498Connect With a Mentor Commented:
class CMyClass
{
public:
static CMyClass* CreateObject(){return new CMyClass();}

static void DestroyObject(CMyClass* cls){delete cls;}
}


Also verify that all functions exported and used outside the DLL are declared as virtual.

Regards,

Gus
0
 
Gus012498Commented:
The class should be created and destroyed in the DLL. Add a static member to the class that allocates a new Object and returns a pointer. Also create a static member that destroys the class.

Regards,

Gus
0
 
mark_sAuthor Commented:
thanks Gus, do you know of an example anywhere that I could look at?
0
 
mark_sAuthor Commented:
thanks Gus, if you answer the question I can give you the points.
0
 
mark_sAuthor Commented:
just noticed you can accept comments as an answer
0
All Courses

From novice to tech pro — start learning today.