COM Object Clean Up

Posted by Reggie McCray on Stack Overflow See other posts from Stack Overflow or by Reggie McCray
Published on 2010-02-25T19:47:26Z Indexed on 2010/04/09 10:03 UTC
Read the original article Hit count: 593

Filed under:
|
|
|
|

What is the difference between the two lines of code below:

CComPtr< IInterface > m_interface;

IInterface* m_interface;

I know that CComPtr help eliminate memory leaks, but I am getting inconsistent results. When declaring the pointer with CComPtr< IInterface > m_interface; and using the interface in my C# code there are no errors, however using the Interface in VC++ I get an unhandled exception error, even if I comment out the instance creation of IInterface.

I am pretty sure the problem is in here somewhere:

STDMETHODIMP CSomeClass::get_IClass(IClass** var)
{ 
      return m_class_var->QueryInterface(var);
}
STDMETHODIMP CSomeClass::putref_IClass(IClass* var)
{ 
     m_class_var = var;
     return S_OK;
}

When I declare the interface pointer with: IInterface* m_interface; I get a RPC_E_SERVERFAULT error when testing the Interface in C# and have to explicitly call GC.Collect() to avoid the error being thrown after instantiation of a few objects. When testing the Interface in VC++ the error is consistent however when it occurs is different. If I comment out the instance creation of IInterface the code runs fine, however when I try to create an instance I get same error as before, just a vague unhandled exception error. What am I doing wrong here?

© Stack Overflow or respective owner

Related posts about com

Related posts about c++