Re: Returning interface pointer from a COM component
CFirstObject :: FinalContructor()
//Here I create the encapsulated COM object
Be aware that CComObject::CreateInstance creates an object with initial
reference count of zero. If you want to keep the pointer long term, it's
a good idea to AddRef it. Otherwise, the object may be destroyed
STDMETHODIMP CFirstObject :: GetLevel1( ILevel1** ppL1)
//Returning to Interface pointer: Which one is among these is
m_objILevel1->QueryInterface(IID_ILevel1, (void**)ppL1 );
QueryInterface already AddRef's.
pLevel1 = (*ppL1);
What's that supposed to achieve?
*ppL1 = (ILevel1*)m_objILevel1;
Both a) and b) would work, once you remove an extraneous AddRef in a).
//Calling interface method from inside
Both would work if DoSomething is a method on ILevel1 interface. a) has
the advantage that you can call any method on CLevel1 class, including
those not exposed via COM.
class ATL_NO_VTABLE CLevel1 : public IDispatchImpl<ILevel1
When you were calling DoSomething above, you weren't passing any
With best wishes,
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925