COM Question
-
I have been reading Visual C++.NET by George Shepherd and I ran into something that didn't quite jive with me. Look at the following first:
struct CSpaceship : IMotion. IDisplay
{
ULONG m_cRef;
//...HRESULT QueryInterface(REFIID riid,
void** ppv);
ULONG AddRef()
{
return InterlockedIncrement(&m_cRef);
}ULONG Release()
{
ULONG cRef = InterlockedIncrement(&m_cRef);
if(cRef == 0)
{
delete this;
return 0;
}
else
return m_cRef;
}//...
};Possibly this isn't a complete implementation of
Release();
but shouldn'tm_cRef
be decremented somewhere inRelease();
? I can't see how theInterlockedIncrement();
could do this because it is being called inAddRef();
as well as in theRelease();
method. -Nick Parker -
I have been reading Visual C++.NET by George Shepherd and I ran into something that didn't quite jive with me. Look at the following first:
struct CSpaceship : IMotion. IDisplay
{
ULONG m_cRef;
//...HRESULT QueryInterface(REFIID riid,
void** ppv);
ULONG AddRef()
{
return InterlockedIncrement(&m_cRef);
}ULONG Release()
{
ULONG cRef = InterlockedIncrement(&m_cRef);
if(cRef == 0)
{
delete this;
return 0;
}
else
return m_cRef;
}//...
};Possibly this isn't a complete implementation of
Release();
but shouldn'tm_cRef
be decremented somewhere inRelease();
? I can't see how theInterlockedIncrement();
could do this because it is being called inAddRef();
as well as in theRelease();
method. -Nick Parker -
I have been reading Visual C++.NET by George Shepherd and I ran into something that didn't quite jive with me. Look at the following first:
struct CSpaceship : IMotion. IDisplay
{
ULONG m_cRef;
//...HRESULT QueryInterface(REFIID riid,
void** ppv);
ULONG AddRef()
{
return InterlockedIncrement(&m_cRef);
}ULONG Release()
{
ULONG cRef = InterlockedIncrement(&m_cRef);
if(cRef == 0)
{
delete this;
return 0;
}
else
return m_cRef;
}//...
};Possibly this isn't a complete implementation of
Release();
but shouldn'tm_cRef
be decremented somewhere inRelease();
? I can't see how theInterlockedIncrement();
could do this because it is being called inAddRef();
as well as in theRelease();
method. -Nick ParkerI think it might be a typo mistake.. i feel it should be interlockeddecrement() function called instead of the increment!! for otherwise.. the component will never die..! or the cref==0 will never happen! as each time the value will always increase! Aravinthan
Visit me:
http://www2.domaindlx.com/earavi/
When you know something.. its meant to share with others :-) for otherwise that knowledge has no worth:-)
mail me:
aravinthan@rediffmail.com