468,777 Members | 2,367 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,777 developers. It's quick & easy.

mscorwks access violation - memory deleted twice?


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

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
0 971

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Allen | last post: by
5 posts views Thread by Boogie El Aceitoso | last post: by
10 posts views Thread by Jonathan Ames | last post: by
reply views Thread by Niklas Pettersson | last post: by
reply views Thread by techie | last post: by
8 posts views Thread by Gary Joy | last post: by
39 posts views Thread by Martin | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.