Hi Matt,

  I'm reviving an old thread...

Matthew wrote:
6. Allow interface_cast_addref<>() to accept interface_ptr arguments
instead of just bare pointers.
This would allow more readable code.
    

This is something that I actually achieved a couple of years ago, and never
got round to releasing. (I'd planned to discuss this as part of a series on
smart pointers for the Smart Pointers column, but that dragged its feet, and
...)

As it stands, it supports code such as the following:

 {
  LPSTREAM  pstm;
  HRESULT   hr = ::CreateStreamOnHGlobal(NULL, true, &pstm);

  IStream_ptr  p(pstm, false);

  IUnknown_ptr punk = comstl2::interface_cast<IUnknown>(p);

  IMalloc_ptr  pstm2 = comstl2::interface_cast<IMalloc>(punk);
 }

I think you'll agree that this is rather good stuff. I will make it a
priority to have this in 1.9.1.
  
Has this actually been done?

I'm having problems using this.
Here's my working code:

   //...
   stlsoft::ref_ptr<IGraphBuilder> pGraph;
   stlsoft::ref_ptr<IMediaControl> pMediaControl;
   //...

   if(SUCCEEDED(co_create_instance(CLSID_FilterGraph, pGraph)))
   {
      pMediaControl.set(interface_cast_addref<IMediaControl*>(pGraph.get()), false);
     //...
When I remove the .get() the whole thing blows up:
      pMediaControl.set(interface_cast_addref<IMediaControl*>(pGraph), false);
The compilation errors are really weird:
--------------------Configuration: ConsoleApp - Win32 Debug--------------------
Compiling...
SequenceProcessor.cpp
h:\adish\dev\stlsoft\include\comstl\conversion\interface_cast.hpp(351) : error C2784: 'I *__cdecl stlsoft::comstl_project::simple_interface_cast(I *)' : could not deduce template argument for ' *' from 'class stlsoft::ref_ptr<struct IGraphBuilder,st
ruct IGraphBuilder,struct IGraphBuilder>'
        h:\adish\dev\stlsoft\include\comstl\conversion\interface_cast.hpp(566) : see reference to function template instantiation '__thiscall stlsoft::comstl_project::interface_cast_base<struct IMediaControl *,struct stlsoft::comstl_project::addref_
release<struct IMediaControl *>,struct stlsoft::comstl_project::ignore_interface_cast_exception>::stlsoft::comstl_project::interface_cast_base<struct IMediaControl *,struct stlsoft::comstl_project::addref_release<struct IMediaControl *>,struct stlso
ft::comstl_project::ignore_interface_cast_exception>(class stlsoft::ref_ptr<struct IGraphBuilder,struct IGraphBuilder,struct IGraphBuilder> &,enum stlsoft::comstl_project::interface_cast_base<struct IMediaControl *,struct stlsoft::comstl_project::ad
dref_release<struct IMediaControl *>,struct stlsoft::comstl_project::ignore_interface_cast_exception>::NullThrowPermission)' being compiled
h:\adish\dev\stlsoft\include\comstl\conversion\interface_cast.hpp(353) : fatal error C1903: unable to recover from previous error(s); stopping compilation
        h:\adish\dev\stlsoft\include\comstl\conversion\interface_cast.hpp(566) : see reference to function template instantiation '__thiscall stlsoft::comstl_project::interface_cast_base<struct IMediaControl *,struct stlsoft::comstl_project::addref_
release<struct IMediaControl *>,struct stlsoft::comstl_project::ignore_interface_cast_exception>::stlsoft::comstl_project::interface_cast_base<struct IMediaControl *,struct stlsoft::comstl_project::addref_release<struct IMediaControl *>,struct stlso
ft::comstl_project::ignore_interface_cast_exception>(class stlsoft::ref_ptr<struct IGraphBuilder,struct IGraphBuilder,struct IGraphBuilder> &,enum stlsoft::comstl_project::interface_cast_base<struct IMediaControl *,struct stlsoft::comstl_project::ad
dref_release<struct IMediaControl *>,struct stlsoft::comstl_project::ignore_interface_cast_exception>::NullThrowPermission)' being compiled
Error executing cl.exe.

I suspect it has something to do with MSVC6.
Any thought?

Thanks,
Adi