Thread overview
[COMSTL; Adi's report] ref_ptr<> as a unit of currency ...
Dec 03, 2006
Matthew
Dec 03, 2006
Matthew
Dec 05, 2006
Adi Shavit
December 03, 2006
> 5. Functions like co_create_instance and other initialization functions expect an address of a pointer as the second argument. This means that when used with interface_ptr, a temporary bare pointer must be used to be given like so:
>
>        // Create a source filter specified by filename
>        interface_ptr<IBaseFilter> pSource; // The interface_ptr<> object
>        {
>           IBaseFilter* ppSource= NULL; // temporary bare pointer
>
>
> if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))
>           {
>             //...
>    return 0;
>           }
>           pSource.set(ppSource, false); // setting the smart pointer.
>        }

Agree that this is not pretty.

> It would be useful to have a method that exposes the internal member so
> it can be used directly in such functions.
> I know it might be dangerous (although there is an option to get the
> referent anyway) but maybe it should be considered.

I can't do this. This is one of the fatal mistakes made in ATL.

I think a better way is to make it a design parameter of COMSTL that interface wrappers - i.e. stlsoft::ref_ptr<X> - are a fundamental unit of currency of the library. Thus, we would then overload the co_create_instance() function suite to work with stlsoft::ref_ptr<..., I> wrappers as well as raw pointers (I), as in:

  {
    const CLSID CLSID_pantheios_COM_LoggerManager  = { 0x4E7D5C47, 0x8F96,
0x45DE, { 0x90, 0x5D, 0xAA, 0x3E, 0x9E, 0x59, 0x2D, 0xE3 } };

    stlsoft::ref_ptr<IDispatch> logmgr;

if(SUCCEEDED(comstl::co_create_instance(CLSID_pantheios_COM_LoggerManager,
logmgr)))
    {
    }
  }

  {
    stlsoft::ref_ptr<IDispatch> logmgr;

if(SUCCEEDED(comstl::co_create_instance(L"{4E7D5C47-8F96-45DE-905D-AA3E9E592
DE3}", logmgr)))
    {
    }
  }

  {
    stlsoft::ref_ptr<IDispatch> logmgr;
    if(SUCCEEDED(comstl::co_create_instance(L"pantheios.COM.LoggerManager",
logmgr)))
    {
    }
  }

This is acceptable in terms of physical coupling because stlsoft/smartptr/ref_ptr.hpp does not include any other headers (except stlsoft/stlsoft.h, of course), so the impact on compilation times and other -ve physical effects will be negligble.

I'd like to hear from anyone who has any opinions on this question, i.e. Should interface wrappers be a fundamental unit of currency in COMSTL?

Cheers

Matthew


December 03, 2006
"Matthew" <matthew@hat.stlsoft.dot.org> wrote in message news:ekt56t$1var$1@digitaldaemon.com...
> > 5. Functions like co_create_instance and other initialization functions expect an address of a pointer as the second argument. This means that when used with interface_ptr, a temporary bare pointer must be used to be given like so:
> >
> >        // Create a source filter specified by filename
> >        interface_ptr<IBaseFilter> pSource; // The interface_ptr<> object
> >        {
> >           IBaseFilter* ppSource= NULL; // temporary bare pointer
> >
> >
> >
if(FAILED(pGraph->AddSourceFilter(a2w(c_str_ptr(filename)),0,&ppSource)))
> >           {
> >             //...
> >    return 0;
> >           }
> >           pSource.set(ppSource, false); // setting the smart pointer.
> >        }
>
> Agree that this is not pretty.
>
> > It would be useful to have a method that exposes the internal member so
> > it can be used directly in such functions.
> > I know it might be dangerous (although there is an option to get the
> > referent anyway) but maybe it should be considered.
>
> I can't do this. This is one of the fatal mistakes made in ATL.
>
> I think a better way is to make it a design parameter of COMSTL that interface wrappers - i.e. stlsoft::ref_ptr<X> - are a fundamental unit of currency of the library. Thus, we would then overload the co_create_instance() function suite to work with stlsoft::ref_ptr<..., I> wrappers as well as raw pointers (I), as in:
>
>   {
>     const CLSID CLSID_pantheios_COM_LoggerManager  = { 0x4E7D5C47, 0x8F96,
> 0x45DE, { 0x90, 0x5D, 0xAA, 0x3E, 0x9E, 0x59, 0x2D, 0xE3 } };
>
>     stlsoft::ref_ptr<IDispatch> logmgr;
>
> if(SUCCEEDED(comstl::co_create_instance(CLSID_pantheios_COM_LoggerManager,
> logmgr)))
>     {
>     }
>   }
>
>   {
>     stlsoft::ref_ptr<IDispatch> logmgr;
>
>
if(SUCCEEDED(comstl::co_create_instance(L"{4E7D5C47-8F96-45DE-905D-AA3E9E592
> DE3}", logmgr)))
>     {
>     }
>   }
>
>   {
>     stlsoft::ref_ptr<IDispatch> logmgr;
>
if(SUCCEEDED(comstl::co_create_instance(L"pantheios.COM.LoggerManager",
> logmgr)))
>     {
>     }
>   }
>
> This is acceptable in terms of physical coupling because stlsoft/smartptr/ref_ptr.hpp does not include any other headers (except stlsoft/stlsoft.h, of course), so the impact on compilation times and other -ve physical effects will be negligble.

Just implemented this one, and it works a treat! Be out in 1.9.1 beta 31. (Oh when will I *ever* release 1.9.1 proper!? <g>)

If you can, I'd appreciate feedback whenever you find a place within the libraries where an interface wrapper should be the means of currency.

Cheers

Matthew


December 05, 2006
Don't know how parse text/html message