Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
tools
vsnet.act
vsnet.debugging
vsnet.documentation
vsnet.enterprise.tools
vsnet.general
vsnet.ide
vsnet.jlca
vsnet.servicepacks
vsnet.setup
vsnet.vsip
vsnet.vss
vsnet.vstools.office
vstudio.development
vstudio.extensibility
vstudio.general
vstudio.helpauthoring
vstudio.setup
vstudio.sourcesafe
  
 
date: Wed, 13 Aug 2008 00:26:13 -0700,    group: microsoft.public.vstudio.general        back       


validating COM pointers in release builds   
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
date: Wed, 13 Aug 2008 00:26:13 -0700   author:   balaji chandan

Re: validating COM pointers in release builds   
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
date: Thu, 14 Aug 2008 10:06:20 +0300   author:   Ismo Salonen

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us