By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,428 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

mscorwks access violation - memory deleted twice?

P: n/a
Hi,

I've created a COM object in VC++ that I call from XMetal. I pass the COM
object (via a XMetal macro) my XMetal Application object by a put_ method.
In my put_ method I call QueryInterface for the _Application interface and
create an instance of a class called CXMetalApp:

STDMETHODIMP CXMLEditorInterface::put_Application(LPDISPATCH newVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
newVal->QueryInterface(__uuidof(XMETAL::_Application),(vo id**)&pXMetalApp);
m_pXMetalApp = new CXMetalApp(pXMetalApp);
}

In the constructor of my CXMetalApp class I store the passed smart pointer
as a member variable:

CXMetalApp::CXMetalApp( XMETAL::_Application pXMetalApp) :
m_pXMetalApp(pXMetalApp){};

The reason for a CXMetalApp class is to encapsulate all my XMetal calls in
that and separate them from other classes. The problem occurs when I close
XMetal. I get a (MSCORWKS.DLL): 0xC0000005: Access Violation error even in
release mode.

I think this could be caused by the XMetal Application object being deleted
twice - firstly when my object is released and then when XMetal actually
closes. I am doing this in the destructor of my COM object:

if (m_pXMetalApp != NULL)
delete m_pXMetalApp;

I'm not explicitly releasing the smart pointer in CXMetalApp. However, when
my COM object is released I think the XMetal Application object is also
deleted. Have I effectively shallow copied my smart pointer? I don't get
an error on the delete above. It happens after that and when memory is
released for my COM object. I am not trying to release any memory in my
XMetal macros. It is done when I close XMetal.

Please can anyone help?
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.