How to close all Objects in C++

Post Reply
evaltuille
Posts: 31
Joined: Wed Jan 09, 2008 1:25 am

How to close all Objects in C++

Post by evaltuille »

Hello again!

In the software i'm developing i'm not able to close it without a break. I think it is a problem of closing properly the CComObjects but I don't know how to do it. I'm using:

For the INPCameraCollection Object:

CComPtr m_spCollection;

m_hExecutionResult = CoInitialize(NULL);
m_hExecutionResult = m_spCollection.CoCreateInstance(CLSID_NPCameraCollection);

m_spCollection->Enum();
m_spCollection->get_Count(&m_CamerasInSystem);
m_spCollection->Item(c, &AuxCamera)

I don't use DispEventAdvise(m_spCollection) like in your sample because if do it, the method Enum() doesn't return OK (but all the next methods work good).

When the aplication ends, I don't close any, only with
CoUnInitialize();


The break is on the file atmcomcli.h:

public:
typedef T _PtrClass;
~CComPtrBase() throw()
{
if (p)
p->Release(); <- On this line
}

And the direction of the p is the same that the direction of the m_spCollection.

Have you got any idea?

Thanks a lot!!
beckdo
Posts: 520
Joined: Tue Jan 02, 2007 2:02 pm

Re: How to close all Objects in C++

Post by beckdo »

Start with this and start adding sections until you can narrow it down:

CoInitialize(NULL);

CComPtr cameraCollection;

cameraCollection.CoCreateInstance(CLSID_NPCameraCollection);

CoUnInitialize();
evaltuille
Posts: 31
Joined: Wed Jan 09, 2008 1:25 am

Re: How to close all Objects in C++

Post by evaltuille »

Thanks a lot!!

It was only a problem in the order!!

I used the INPCameraCollection like a global variable in my project, but used it only in the method I use it, it works properly.

Thanks a lot.
Post Reply