How to convert an IOutputStream object to an ISequentialStream?

Woods Sea 5 Reputation points
2024-09-04T08:36:02.8833333+00:00

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!

Universal Windows Platform (UWP)
Windows Server Printing
Windows Server Printing
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Printing: Printer centralized deployment and management, scan and fax resources management, and document services
674 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.