473,402 Members | 2,064 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,402 software developers and data experts.

Deletion of a COM object in VC6.0

I have a project that contains a COM object running in the in-process
configuration. The project was developed by VC6.0 with SP 3. The project has
been put into production for long period of time and it worked just fine.
Right now, I want to migrate the project to VC7.1. During the migration, I
find that there is a bug in the COM object: The COM object has wrongly
Release() for two times, which result in the reference counter to COM object
to 0, triggering the COM object to be deleted in VC7.1 code. This bug is
supposed to be the same as in the VC6.0 code. However, I found that, when the
reference counter reaches 0(or even a negative value), the VC6.0 code does
not delete the COM object and this COM object remains in the COM space. I am
wondering:
1. When the reference counter reaches 0, if the VC6.0 code does not delete
the COM object immediately, who and when will perform the deletion of the COM
object?
2. Why the behavior in the VC7.1 has been changed?

Sample code:
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv1);
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv2);
ppv2->Release();
ppv2->Release();// In VC7.1, the object of IID_XXXX is deleted immediately;
// In VC6.0, the object of IID_XXXX would not be
deleted
Nov 17 '05 #1
4 1457
lauch2 wrote:
I have a project that contains a COM object running in the in-process
configuration. The project was developed by VC6.0 with SP 3. The
project has been put into production for long period of time and it
worked just fine. Right now, I want to migrate the project to VC7.1.
During the migration, I find that there is a bug in the COM object:
The COM object has wrongly Release() for two times, which result in
the reference counter to COM object to 0, triggering the COM object
to be deleted in VC7.1 code. This bug is supposed to be the same as
in the VC6.0 code. However, I found that, when the reference counter
reaches 0(or even a negative value), the VC6.0 code does not delete
the COM object and this COM object remains in the COM space. I am
wondering:
1. When the reference counter reaches 0, if the VC6.0 code does not
delete the COM object immediately, who and when will perform the
deletion of the COM object?
2. Why the behavior in the VC7.1 has been changed?

Sample code:
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv1);
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv2);
ppv2->Release();
ppv2->Release();// In VC7.1, the object of IID_XXXX is deleted
immediately; // In VC6.0, the object of
IID_XXXX would not be
deleted


There's got to be something more to the story that you're overlooking. For
any correctly functioning COM object, a single call to Release() after
CoCreateInstance will destroy the object. Nothing about this has changed in
VC7.1 - it's all called out by the COM specification.

-cd
Nov 17 '05 #2


"Carl Daniel [VC++ MVP]" wrote:
lauch2 wrote:
I have a project that contains a COM object running in the in-process
configuration. The project was developed by VC6.0 with SP 3. The
project has been put into production for long period of time and it
worked just fine. Right now, I want to migrate the project to VC7.1.
During the migration, I find that there is a bug in the COM object:
The COM object has wrongly Release() for two times, which result in
the reference counter to COM object to 0, triggering the COM object
to be deleted in VC7.1 code. This bug is supposed to be the same as
in the VC6.0 code. However, I found that, when the reference counter
reaches 0(or even a negative value), the VC6.0 code does not delete
the COM object and this COM object remains in the COM space. I am
wondering:
1. When the reference counter reaches 0, if the VC6.0 code does not
delete the COM object immediately, who and when will perform the
deletion of the COM object?
2. Why the behavior in the VC7.1 has been changed?

Sample code:
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv1);
CoCreateInstance(CLSID_XXX, NULL, CLSCTX_ALL, IID_XXXX,(void**)ppv2);
ppv2->Release();
ppv2->Release();// In VC7.1, the object of IID_XXXX is deleted
immediately; // In VC6.0, the object of
IID_XXXX would not be
deleted


There's got to be something more to the story that you're overlooking. For
any correctly functioning COM object, a single call to Release() after
CoCreateInstance will destroy the object. Nothing about this has changed in
VC7.1 - it's all called out by the COM specification.

-cd

Thanks for the reply.

In fact, I am not familar with the COM development. Anyway, the real
situation is as below:

My COM object is derived from the ATL class. Assume the COM object name is
MyComObject. Since the COM object is generated by the VC6.0's wizard, there
should be CMyComObject and IMyComObject classes generated as follows:
class ATL_NO_VTABLE CMyComObject:
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<IMyComObject, &CLSID_MyComObject>,
public IDispatchImpl<IMyComObject, &IID_IMyComObject, &LIBID_MSQLib>
{
…
};

interface ImsqSendQueue : IDispatch
{
....
};

The sample should be as follows:
IMyComObject* pMyComObject1;
IMyComObject* pMyComObject2;

CoCreateInstance(CLSID_MYCOMOBJECT, NULL, CLSCTX_ALL, IID_
MYCOMOBJECT,(void**) &pMyComObject1);
CoCreateInstance(CLSID_ MYCOMOBJECT, NULL, CLSCTX_ALL, IID_
MYCOMOBJECT,(void**) &pMyComObject2);
pMyComObject2->Release();
pMyComObject2->Release(); // see the source code below

I also trace into the Release() function, here is implementation of
Release() in vc7.1 and vc6.0:
----------------------------------------------------------------------------------
vc7.1:-
template <class Base>
class CComObjectCached : public Base
{
STDMETHOD_(ULONG, Release)() throw()
{
m_csCached.Lock();
InternalRelease();
ULONG l = m_dwRef;
m_csCached.Unlock();
if (l == 0)
delete this;
else if (l == 1)
_pAtlModule->Unlock();
return l;
}
};
----------------------------------------------------------------------------------
vc6.0:-
template <class Base>
class CComObjectGlobal : public Base
{
STDMETHOD_(ULONG, AddRef)() {return _Module.Lock();}
}

class CComModule : public _ATL_MODULE
{
LONG Unlock()
{
return CComGlobalsThreadModel::Decrement(&m_nLockCnt);
}
};
----------------------------------------------------------------------------------

Any idea?

Thanks,
lauch2.

Nov 17 '05 #3
sorry, should be:
interface IMyComObject : IDispatch
instead of:
interface ImsqSendQueue : IDispatch

Nov 17 '05 #4
lauch2 wrote:
"Carl Daniel [VC++ MVP]" wrote:
There's got to be something more to the story that you're
overlooking. For
any correctly functioning COM object, a single call to Release()
after CoCreateInstance will destroy the object. Nothing about this
has changed in VC7.1 - it's all called out by the COM specification.

-cd

Thanks for the reply.

In fact, I am not familar with the COM development. Anyway, the real
situation is as below:


I'm not an ATL user, so rather than speculate, I'll just suggest that you
re-post in

microsoft.public.vc.atl

where you're more likely to find an ATL expert to help. It usually helps if
you can produce (and post) a minimal sample program that exhibits the
behavior you're trying to understand as well.

-cd
Nov 17 '05 #5

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

Similar topics

2
by: Christopher Pisz | last post by:
currently my node is like so with everything public: class Quadtree_Node { public: Quadtree_Node(Quadtree_Node * parent, Bounding_Box & bounds); ~Quadtree_Node(); void Subdivide(float...
7
by: Morten Aune Lyrstad | last post by:
Here's the deal: I'm looping through a collection of listener class objects like this: (illustration code only) AClass::ThrowEvent() { for (int i = 0; i < numListeners; i++) {...
3
by: jaws | last post by:
My problems is as follows. Hope you guys can provide some insight. 1. I have a class which opens a file and simply spits out the text. Methods in place to open, print, close, and delete the...
0
by: Dalan | last post by:
Although I have been able to prevent the deletion of keywords in a separate Access 97 combo box table, the code that I'm using probably requires updating because of the strange error messages that...
7
by: TJS | last post by:
javascript "confirm" fires after deletion instead of before deletion. how do I get this to stop the processing ? code ================== Sub ShowAlert(ByVal s As string)...
3
by: A_Republican | last post by:
I am interested in writing my own secure file deletion program. I want to be able to read and write to my hard drive directly. My application will seach my hard drive for all locations marked for...
2
by: James Vanns | last post by:
How would one go about testing for the deletion of a file that sits under an ostream object? I've tried is_open, good(), fail(), eof(), bad() and catching exceptions - nothing! Aparently the <<...
1
by: Aff | last post by:
Dear Brothers, i am facing a problem class compactdisc { char title;/string a; int capacity; public:
4
by: lokki | last post by:
Hello, can anybody tell me what's wrong with following example code? char *k, *v; k = new char; strcpy(k, "a2"); v = new char;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.