Windows Vista Beta | WinVistaBeta.com - Message | validating COM pointers in release builds

November 20, 2008  
Subject: validating COM pointers in release builds
Group: microsoft.public.vstudio.general
Date: 8/13/2008 12:26:13 AM
From: =?Utf-8?B?YmFsYWppIGNoYW5kYW4=?= [Email Address Protection]

I am using a piece of code like this:

CDOCSObject * pObject = NULL;
map<CString, CDOCSObjectCacheItem *>::iterator cacheItr =
m_DOCSObjectCache.find(strID);
if ( cacheItr != m_DOCSObjectCache.end() )
{
pObject = (*cacheItr).second->m_pObject;
pObject->AddRef();
}
return pObject;

pObject->AddRef() is throwing an access violation error in release builds.

I tried to validate pObject using
if(pObject != NULL) and IsBadReadPtr() etc but doesnt help.
It still throws same error in release build. Is there a way to check for
validity of COM pointer in release build.

Thanks in advance
Chandan


Back
Subject: Re: validating COM pointers in release builds
Group: microsoft.public.vstudio.general
Date: 8/14/2008 12:06:20 AM
From: Ismo Salonen [Email Address Protection]

balaji chandan wrote:
> I am using a piece of code like this:
>
> CDOCSObject * pObject = NULL;
> map<CString, CDOCSObjectCacheItem *>::iterator cacheItr =
> m_DOCSObjectCache.find(strID);
> if ( cacheItr != m_DOCSObjectCache.end() )
> {
> pObject = (*cacheItr).second->m_pObject;
> pObject->AddRef();
> }
> return pObject;
>
> pObject->AddRef() is throwing an access violation error in release builds.
>
> I tried to validate pObject using
> if(pObject != NULL) and IsBadReadPtr() etc but doesnt help.
> It still throws same error in release build. Is there a way to check for
> validity of COM pointer in release build.
>
> Thanks in advance
> Chandan
>
It throws an exception ? Have you tried catching it and checking
the errorcode ? This can be used when the pointer is valid com pointer
and the server died for some reason.

But why you are doing AddRef() here ? If you need the singleton model
then maybe you should write your own singleton class to handle caching.

br
ismo

br ismo

Back