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

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

问题描述

在.NET 3.0项目中,我需要通过P / Invoke
(特别是对于PrintTicket Provider函数,如PTConvertPrintTicketToDevMode())进行一些调用。

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

框架具有COM IStream接口的托管定义:
System.Runtime.InteropServices.ComTypes.IStream

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

我需要这个作为System.IO.Stream,使我可以很容易地使用.NET类(如XmlDocument)与这些导入的函数的输出。但我不能看到一个不太痛苦的方式来回转换为 System.IO.Stream ,而不是一次读取和写入数据块。

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.

还是我走错了路?

我有 PTConvertPrintTicketToDevMode < a>()import as:

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);


推荐答案

这不是很简单在框架中的方式),但是想法是实现一个实现System.Runtime.InteropServices.ComTypes.IStream的类。这里是一篇有代码的文章。文章没有实现Write方法,但应该是另一个10分钟写。一探究竟。 http://www.sturmnet.org/blog/ archives / 2005/03/03 / cds-csharp-extractor

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天全站免登陆