Creating IStream object in C#

前端 未结 4 1973
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 07:18

I\'m writing a project and working with another party DLL.

Function from their DLL wants an IStream object to save result, but I can\'t understand how to create an I

相关标签:
4条回答
  • 2021-01-14 07:43

    You don't create IStream object, because obviously it's an interface. You should rather implement this interface and pass your object. Or simply use an object that already implements it, if such object exists.

    Already given answer for a similar question gives a nice example how to use IStream interface in C#.

    Does a wrapper class for a COM interop IStream already exist?

    Correction: This, however, works only if you need to use already an existing IStream inside your app, not when you need to create and pass an IStream elsewhere. For that task, see this for refence how to do that:

    http://msdn.microsoft.com/en-us/library/windows/desktop/aa380034(v=vs.85).aspx

    And here is an example from Microsoft (used for XmlLite, not sure if it works for you)

    http://msdn.microsoft.com/en-us/library/windows/desktop/ms752876(v=vs.85).aspx

    Or maybe this example, already posted by Marcus: http://hl7connect.blogspot.sk/2010/04/c-implementation-of-istream.html

    This last link shows how to use any Stream to implement the IStream interface.

    0 讨论(0)
  • 2021-01-14 07:47

    IStream I assume is an interface. You cannot create an instance from an interface directly, rather you create an instance of an object that implements that interface (or create your own object that implements IStream).

    0 讨论(0)
  • 2021-01-14 07:49

    Here is a managed implementation from Microsoft now that .Net is more open source:

    https://referencesource.microsoft.com/#PresentationFramework/src/Framework/MS/Internal/IO/Packaging/managedIStream.cs

    0 讨论(0)
  • 2021-01-14 07:51

    Implement your own stream class and inherit the IStream interface. IStream is just a stream and can be pretty much what you decide it is as long as it is a stream (e.g. FileStream etc.)

    Related: link

    0 讨论(0)
提交回复
热议问题