Re: Adding member variables crashes app
CIDriver, CDriver and CMyDriver all have virtual destructors.
__declspec(dllexport) CIDriver* InitDriver(CIKernel* i_hKernel)
{
//__asm { int 0x03 }
CMyDriver* hUserDriver = new CUserDriver;
hUserDriver->Create(i_hKernel);
return (CIDriver *)hUserDriver;
}
__declspec(dllexport) void EndDriver(CIDriver* i_hIDriver)
{
CMyDriver * hUserDriver = (CMyDriver *)i_hIDriver;
hUserDriver->Destroy();
delete hUserDriver;
}
My app crashes at the 'delete hUserDriver'. EndDriver is an exposed
interface call that another DLL calls to detroy the driver.
hUserDriver->Destroy() destroy all internal structures of CDriver (not
CMyDriver, as this function isnt overloaded in CMyDriver). CMyDriver is not
referencing any objects destroyed by the Destroy call. Nothing is available
in the debugger as its all assembly at that point.
In the class definition for CMyDriver, if I add public member variables, it
crashes on the delete. If I make them global (file scope), it doesnt crash.
I"m wondering if its looking at the class size or something. I'm just
confused.
I'd add the code snippet, but I'm not doing anything special that would look
weird.
"Tom Widmer [VC++ MVP]" wrote:
Charles R wrote:
Hi!
We have a class CDriver which inherits from IDriver. CDriver is defined in
a library, CDriver.lib. CDriver.lib is added to the library definition of
the project settings, and we have CDriver.h included in the file list for the
project.
If we create a new class, CMyDriver, which inherits from CDriver, and add
member variables to it, when we run the app, things crash when the destructor
is called. If we remove the member variables things work properly. We can
add as many member functions as we want, but cannot add member variables.
We dont understand that's happening. Any ideas? This is basic inheritance!!
This is weird that I cannot add member variables.
Help!?!?!?
Does IDriver have a virtual destructor? That is required if you are
deleting a CMyDriver object through an IDriver pointer.
If that's not the problem, then you haven't given us enough information
to work it out.
Tom