Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Returning an implemented interface

0 views
Skip to first unread message

Barzo

unread,
Oct 10, 2009, 11:49:10 AM10/10/09
to
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.

Igor Tandetnik

unread,
Oct 10, 2009, 3:01:59 PM10/10/09
to
Barzo wrote:
> 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));
> };

pVal is already a double pointer. Remove the ampersand.
--
With best wishes,
Igor Tandetnik

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

Barzo

unread,
Oct 12, 2009, 3:04:39 AM10/12/09
to
On 10 Ott, 21:01, "Igor Tandetnik" <itandet...@mvps.org> wrote:
>
> > 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));
> > };
>
> pVal is already a double pointer. Remove the ampersand.

Oh damn! :-)
What a single letter may do!

Thanks Igor!

0 new messages