Search code examples
c++windowscomistream

Windows IStream interface on std::istream


Within C++ on Windows, is there any easy way to create a (COM) IStream interface to an existing std::stream object?

An example would be to read an image with IWICStream::InitializeFromIStream() from std::cin.


Solution

  • There is no standard implementation for that. You need to write your class (or find a third-party one) that implements the IStream interface and internally delegates to an std::stream as needed. However, you are likely to have trouble implementing IStream::Stat(), which is commonly used to retrieve a stream's data size. In the case of std::cin, you would not know how much data is being provided.