System.Runtime.InteropServices.ComTypes.IStream到的System.IO.Stream [英] System.Runtime.InteropServices.ComTypes.IStream to System.IO.Stream

查看:477
本文介绍了System.Runtime.InteropServices.ComTypes.IStream到的System.IO.Stream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个.NET 3.0的项目,我需要通过P / Invoke的几个电话 (具体到像PTConvertPrintTicketToDevMode的打印标签提供功能())。

该框架拥有COM IStream接口的管理的定义: <一href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comtypes.istream_members.aspx"相对=nofollow title="System.Runtime.InteropServices.ComTypes.IStream">System.Runtime.InteropServices.ComTypes.IStream

我需要这个作为的System.IO.Stream,这样我可以轻松地使用.NET类(如XmlDocument的)与这些进口函数的输出。但我不能看到这来回转换的的System.IO.Stream 其他不是在同一时间读取和写入数据的字节块。它似乎太kludgey的任务似乎很常见的。

还是我在这个错误的方式?

我有 PTConvertPrintTicketToDevMode ()导入为:

  [的DllImport(prntvpt.dll)
    公共静态外部INT
    PTConvertPrintTicketToDevMode(IntPtr的hProvider,
                                  的IStream pPrintTicket,
                                  EDefaultDevmodeType baseDevmodeType,
                                  EPrintTicketScope范围,
                                  IntPtr的pcbDevmode,
                                  出的IntPtr ppDevmode,
                                  [的MarshalAs(UnmanagedType.BStr)出字符串pbstrErrorMessage);
 

解决方案

这不是真的简单的(即没有内置的方式来做到这一点的框架),但这个想法是落实实现系统的一类。 Runtime.InteropServices.ComTypes.IStream。下面是与code的文章。本文不实现Write方法,但它应该是另外的10分钟的时间写的。一探究竟。 http://www.sturmnet.org/blog/archives / 2005/03/03 / CDS-CSHARP解压

In a .NET 3.0 project, I need to make some calls via P/Invoke (specifically to the PrintTicket Provider functions like PTConvertPrintTicketToDevMode() ).

The framework has a managed definition of the COM IStream interface: System.Runtime.InteropServices.ComTypes.IStream

I need this as System.IO.Stream so that I can easily use .NET classes (like XmlDocument) with the output of these imported functions. But I can't see a less painful way of converting this back and forth to System.IO.Stream other than reading and writing data a block of bytes at a time. It seems too kludgey for a task that would seem very common.

Or am I going at this the wrong way?

I have PTConvertPrintTicketToDevMode() imported as:

    [DllImport("prntvpt.dll")]
    public static extern int 
    PTConvertPrintTicketToDevMode(IntPtr hProvider, 
                                  IStream pPrintTicket,
                                  EDefaultDevmodeType baseDevmodeType,
                                  EPrintTicketScope scope,
                                  IntPtr pcbDevmode,
                                  out IntPtr ppDevmode,
                                  [MarshalAs(UnmanagedType.BStr)]out String pbstrErrorMessage);

解决方案

It's not really straightforward (ie. there is no built in way to do it in the framework), but the idea is to implement a class that implements System.Runtime.InteropServices.ComTypes.IStream. Here is an article with the code. The article does not implement the Write method, but it should be another 10 minutes to write that. Check it out. http://www.sturmnet.org/blog/archives/2005/03/03/cds-csharp-extractor

这篇关于System.Runtime.InteropServices.ComTypes.IStream到的System.IO.Stream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆