473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

mscorwks access violation - memory deleted twice?

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Allen | last post by:
Hi all, I tried posting to one of the ms.win32 groups and haven't gotten a response yet. It may be my C++ that's at fault anyway so I'll try here too. I wrote a .dll that is misbehaving...
5
by: Boogie El Aceitoso | last post by:
Hi, The code below produces an access violation error, complaining that an object is destroyed twice. I don't understand why this happens. Any help would be appreciated. ...
10
by: Jonathan Ames | last post by:
Moving to C++ from Java, I'm still confused by some aspects of memory cleanup operations. For example, let's say I have a class MovingObject which maintains a pointer to another class...
0
by: Niklas Pettersson | last post by:
A deffinite bug in mscorwks.dll makes my managed service crash abruptly. When hooking up windbg it turns out to be an "access violation" in the mscorwks assembly memory space. Every time it happens...
1
by: BillyO | last post by:
In the attached code fragment I have a buffer overflow and a memory access violation. When I run the code .Net fails to verify the IL because of the buffer overflow and I get an exception as...
0
by: techie | last post by:
I have created an event sink in my ATL COM project. The event sink receives events from a C# component. There is no problem with receiving events but when my COM object is released I get an...
8
by: Gary Joy | last post by:
I really am banging my head with this one... I have a regular unmanaged C++ application that is using mixed DLLs to (amongst other things) call a C# back-end (which is using ADO .NET). I am...
6
by: Zytan | last post by:
I ran through the VB Guided Tour some time ago. In particular, the "Managing Your Records: Using Data in Your Program" section: http://msdn2.microsoft.com/en-us/library/t25kbx0s(VS.80).aspx ...
39
by: Martin | last post by:
I have an intranet-only site running in Windows XPPro, IIS 5.1, PHP 5.2.5. I have not used or changed this site for several months - the last time I worked with it, all was well. When I tried it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.