c++ - Release Interface pointers -


I, in some smart signal class desiccator, have declared the member variable within a class to free this interface The code, which is better, is:

Members varible

  CComQIPtr & lt; IMyInterFace & gt; m_pMyInterface;   

constructor

  m_pMyInterface.CreateInstace (CLSID_MyInterface); Destructive in   

  if (m_pMyInterface) m_pMyInterface.Release ();   

Or should it be

  if (m_pMyInterface.p = zero!) M_pMyInterface.Release ();   

The above form which is a better one and the way I am using interface pointsers there is a flaw. Tom

~ CComQIPtr The Destructor takes care of everyone to explicitly release you There is no need to do so, if you want, to reuse the variable, you can do either of the two:

  • m_pMyInterface.Release ();
  • m_pMyInterface = Zero;

    With zero (operator = CComPtr , with CComQIPtr may be unclear) Works) check is not required, the CComQIPtr :: release method does this anyway.

Comments

Popular posts from this blog

asp.net - Procedure or function "Procedure name" expects a parameter "Param name" which was not supplied occurs rarely -

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -

c++ - Redefined variable in the other module -