none
Conversion COM IStream to std::istream

    Question

  • Hi there,

    I'm pretty new with COM and I have a problem to convert COM interface IStream to std::istream!

    Point is, I need this conversion to read image file using the libtiff, and I only can use std::istream or std::ostream...

    I read some topic about that, I need to provide my own class derived from std::streambuf, but then what I'm suppose to write in it?

    If anyone could lead me in this situation or provides me examples, would be great!

    Thanks for answers,

    Best Regard,

    Mike

    Tuesday, February 28, 2012 10:01 AM

Answers

  • On 28/02/2012 11:01, MikeFr77 wrote:

    I'm pretty new with COM and I have a problem to convert COM interface IStream to std::istream!

    Point is, I need this conversion to read image file using the libtiff, and I only can use std::istream or std::ostream...

    If you use libtiff (and TIFFOpen doesn't fit your needs), you may consider using TIFFClientOpen with your IStream directly, without passing through C++ streams:

    http://www.libtiff.org/man/TIFFOpen.3t.html

    Giovanni

    • Marked as answer by Helen Zhao Wednesday, March 07, 2012 1:40 AM
    Tuesday, February 28, 2012 10:41 AM
  • On 28/02/2012 11:01, MikeFr77 wrote:

    I'm pretty new with COM and I have a problem to convert COM interface IStream to std::istream!

    Point is, I need this conversion to read image file using the libtiff, and I only can use std::istream or std::ostream...

    I read some topic about that, I need to provide my own class derived from std::streambuf, but then what I'm suppose to write in it?

    In addition to the other suggestions, note that Boost offers an Iostreams library which seems to simplify the development of custom streams.

    You can implement a "Source" class which exposes a read() method that reads data using IStream methods (e.g. ISequentialStream::Read() method).

    There is a tutorial on Boost web site on writing a "Source" class to read data from STL containers; you can modify it to use IStream instead:

    http://www.boost.org/doc/libs/1_43_0/libs/iostreams/doc/tutorial/container_source.html

    Giovanni

    • Marked as answer by Helen Zhao Wednesday, March 07, 2012 1:40 AM
    Tuesday, February 28, 2012 11:07 AM

All replies

  • I have search the net and found this. It may be starting point for you.

    http://stackoverflow.com/questions/2885280/stdostream-interface-to-an-ole-istream

    Tuesday, February 28, 2012 10:29 AM
  • On 28/02/2012 11:01, MikeFr77 wrote:

    I'm pretty new with COM and I have a problem to convert COM interface IStream to std::istream!

    Point is, I need this conversion to read image file using the libtiff, and I only can use std::istream or std::ostream...

    If you use libtiff (and TIFFOpen doesn't fit your needs), you may consider using TIFFClientOpen with your IStream directly, without passing through C++ streams:

    http://www.libtiff.org/man/TIFFOpen.3t.html

    Giovanni

    • Marked as answer by Helen Zhao Wednesday, March 07, 2012 1:40 AM
    Tuesday, February 28, 2012 10:41 AM
  • On 28/02/2012 11:01, MikeFr77 wrote:

    I'm pretty new with COM and I have a problem to convert COM interface IStream to std::istream!

    Point is, I need this conversion to read image file using the libtiff, and I only can use std::istream or std::ostream...

    I read some topic about that, I need to provide my own class derived from std::streambuf, but then what I'm suppose to write in it?

    In addition to the other suggestions, note that Boost offers an Iostreams library which seems to simplify the development of custom streams.

    You can implement a "Source" class which exposes a read() method that reads data using IStream methods (e.g. ISequentialStream::Read() method).

    There is a tutorial on Boost web site on writing a "Source" class to read data from STL containers; you can modify it to use IStream instead:

    http://www.boost.org/doc/libs/1_43_0/libs/iostreams/doc/tutorial/container_source.html

    Giovanni

    • Marked as answer by Helen Zhao Wednesday, March 07, 2012 1:40 AM
    Tuesday, February 28, 2012 11:07 AM
  • Thanks for replies guys! I'll check links you gave to me!

    Another question, I'm able to convert my IStream into BYTE*.

    It will not be easier to do this and then use the BYTE* to create a std::(i)ostream ???

    Mike.

    Tuesday, February 28, 2012 1:41 PM
  • Hi Mike,

    I am checking the thread status on my side. Would you please let me know the result of these suggestions? If you the issue have been solved, please mark the reply which helps you as answer, or you can post your solution here. If you need further help, please feel free to let us know and provide more information about the issue. We'll continue working with you on it.

    Thanks for your understanding.
    Best regards,  


    Helen Zhao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 05, 2012 3:47 AM