How to convert an IOutputStream object to an ISequentialStream?
Woods Sea
5
Reputation points
I want to convert an IOutputStream object to an ISequentialStream, the following is my sample code:
ComPtr<ISequentialStream> ConvertOutputStreamToSequentialStream(_In_ IOutputStream^ outputStream)
{
ComPtr<ISequentialStream> sequentialStream = nullptr;
ComPtr<IUnknown> unknown(reinterpret_cast<IUnknown*>(outputStream));
ComPtr<IRandomAccessStream> randomAccessStream;
//ComPtr<IStream> randomAccessStream;
HRESULT hr = unknown.As(&randomAccessStream);
if (FAILED(hr))
{
return nullptr;
}
ComPtr<IStream> stream;
hr = CreateStreamOverRandomAccessStream(randomAccessStream.Get(), IID_PPV_ARGS(&stream));
if (FAILED(hr))
{
return nullptr;
}
hr = stream.As(&sequentialStream);
if (FAILED(hr))
{
return nullptr;
}
return sequentialStream;
}
But I encountered a compile error C3699: '*': cannot use this indirection on type 'Windows::Storage::Streams::IRandomAccessStream'.
I found it caused by the sentence:
ComPtr<IRandomAccessStream> randomAccessStream;
Can any one help me please?
Thanks a lot in advance!
Sign in to answer