Board index » cppbuilder » COM smart pointers for BCB3

COM smart pointers for BCB3

I am having problems referencing a IDispatch pointer to a Interface derived
from an IDispath pointer
the following is the code.

STDMETHODIMP TPanagonCtxMenuImpl::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi,
VARIANT vaObject)
{
//vaObject is a pointer to an IDispatch

 HRESULT             hr = E_INVALIDARG;
  AnsiString          asFile, asDir;
  IFnDocumentDual  *pDualDoc;  //IFnDocumentDual is an interface derived
from IDispacth.

// I would like to do the following which I know I can not

pDualDoc = vaObject.pdispVal.

MFC provides a COM utils functions whicha allow COM manipulation.  One of
the functions is called _com_ptr_t
which produces a COM smart pointer.  The COM smart pointer overloads the =
so that the above equation works
Is there a BCB3 version of this.  If not how would I do this in BCB3.  It
looks like I might need to use AddRef() and
other IDispatch stuff.  I am fairly new at COM and do not fully understand
IDispatch.

 

Re:COM smart pointers for BCB3


Hello,

If you know the exact interface pointer types you're handling you should be
able to use the TComInterface class from utilcls.h:

TComInterface <IDispatch> pDisp (vaObject.pdispVal, true);
pDisp->Whatever ();

have fun,
--
Binh Ly
Brickhouse Data Systems, Inc.
http://www.brickhouse.com

Quote
David Suess wrote in message <72k081$i...@forums.borland.com>...
>I am having problems referencing a IDispatch pointer to a Interface derived
>from an IDispath pointer
>the following is the code.

>STDMETHODIMP TPanagonCtxMenuImpl::InvokeCommand(LPCMINVOKECOMMANDINFO
lpcmi,
>VARIANT vaObject)
>{
>//vaObject is a pointer to an IDispatch

> HRESULT             hr = E_INVALIDARG;
>  AnsiString          asFile, asDir;
>  IFnDocumentDual  *pDualDoc;  //IFnDocumentDual is an interface derived
>from IDispacth.

>// I would like to do the following which I know I can not

>pDualDoc = vaObject.pdispVal.

>MFC provides a COM utils functions whicha allow COM manipulation.  One of
>the functions is called _com_ptr_t
>which produces a COM smart pointer.  The COM smart pointer overloads the =
>so that the above equation works
>Is there a BCB3 version of this.  If not how would I do this in BCB3.  It
>looks like I might need to use AddRef() and
>other IDispatch stuff.  I am fairly new at COM and do not fully understand
>IDispatch.

Other Threads