C++ Converting ComPtr to ComPtr

When using WRL, sometimes if you have a pointer to derived interface such as IRandomAccessStream (which derives from IClosable), and you would want to convert it to IClosable (so that you can call "Close" on the stream). To do that you will have to use ComPtr.As call.


  WRL::ComPtr< Streams::IRandomAccessStream > randomAccessStream;
 // set randomAccessStream to something here.

 WRL::ComPtr< IClosable > pICloseable;
 HRESULT hr = randomAccessStream.As< IClosable >( &pICloseable );
 if( SUCCEEDED( hr ) )
 pICloseable->Close(); // Call Close on Stream