4

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.

Hugues
  • 2,865
  • 1
  • 27
  • 39
  • IStream is an interface, it is up to you to provide the implementation. You'd generally only have to implement Read and Seek, return E_NOTIMPL for the rest. Don't try to read binary data from a text stream like std::cin. – Hans Passant Jun 20 '14 at 17:36
  • @HansPassant it's OK to read binary data from `cin` if you set it up properly first: https://stackoverflow.com/a/11259588/5987. No reason that piping should be crippled on Windows. – Mark Ransom Apr 26 '18 at 15:52

1 Answers1

4

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770