Returning an implemented interface
Hi,
in my library I have a situation like this where the coclass
implements IA, IB and IDisp:
[
object,
uuid(.....),
oleautomation,
nonextensible,
pointer_default(unique)
]
Interface IA : IUnknown
{
methodA(...)
}
[
object,
uuid(.....),
oleautomation,
nonextensible,
pointer_default(unique)
]
Interface IB : IUnknown
{
methodB(...)
}
[
dual,
nonextensible,
hidden
]
Interface IDisp : IDispatch
{
HRESULT Get_IA([out, retval] IA** pVal);
HRESULT Get_IB([out, retval] IB** pVal);
}
library MyLib
{
.....
[
uuid(AB566C81-AF54-11DE-B5BE-00A0D15E9B20),
helpstring("AudioLib Class")
]
coclass MyClass
{
Interface IA;
Interface IB;
[default] interface IDisp;
};
}
The implementation of the IDisp Get methods are:
STDMETHODIMP CMyClass::Get_IA(IA** pVal)
{
if (!pVal) return E_POINTER;
return this->QueryInterface(IID_IA, reinterpret_cast<void**>
(&pVal));
};
//------------------------------------------------------------------------------
STDMETHODIMP CMyClass::Get_IB(IB** pVal)
{
if (!pVal) return E_POINTER;
return this->QueryInterface(IID_IB, reinterpret_cast<void**>
(&pVal));
};
Now when, in a VB6 client, I do this:
---------------------------------------------------------------
Dim p As MyClass
Private Sub Form_Load()
Set p = New MyClass
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set p = Nothing
End Sub
---------------------------------------------------------------
The object is created and destroyed well, but if I call Get_IB or
Get_IA:
---------------------------------------------------------------
Private Sub Form_Load()
Set p = New MyClass
With p.Get_IB
' No code here....
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set p = Nothing
End Sub
---------------------------------------------------------------
The object p is not destroyed (the MyClass::FinalRelease is not
called).
Why this happens? Where I wrong?
Thanks,
Daniele.