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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Gus012498Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.