本文介绍了如何在idl中声明IStream,以便Visual Studio将其映射到s.w.interop.comtypes?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个COM对象,该对象需要从C#客户端获取流并对其进行处理.看来我应该使用IStream.所以我像下面这样写我的idl.然后,我使用MIDL编译为tlb,并编译我的解决方案,注册它,然后将对我的库的引用添加到C#项目中.

I have a COM object that takes needs to take a stream from a C# client and processes it. It would appear that I should use IStream. So I write my idl like below. Then I use MIDL to compile to a tlb, and compile up my solution, register it, and then add a reference to my library to a C# project.

Visual Studio在我自己的库中创建一个IStream定义.如何阻止它执行此操作,并使其使用COMTypes IStream?似乎会有3个答案之一:添加一些导入

Visual Studio creates an IStream definition in my own library. How can I stop it from doing that, and get it to use the COMTypes IStream? It seems there would be one of 3 answers:add some import

  • 向idl发送,因此它不会重新声明IStream(导入MSCOREE即可,但不能解决C#问题)
  • 以某种方式在Visual Studio中对IStream进行了别名-但我不知道如何做到这一点.
  • 我所有的想法都是完全错误的,我完全不应该使用IStream

帮助...谢谢

[
  uuid(3AC11584-7F6A-493A-9C90-588560DF8769),
  version(1.0),
]
library TestLibrary
{

  importlib("stdole2.tlb");

  [
    uuid(09FF25EC-6A21-423B-A5FD-BCB691F93C0C),
    version(1.0),
    helpstring("Just for testing"),
    dual,
    nonextensible,
    oleautomation
  ]
  interface ITest: IDispatch
  {
    [id(0x00000006),helpstring("Testing stream")]
    HRESULT _stdcall LoadFromStream([in] IStream * stream, [out, retval] IMyTest ** ResultValue);
  };

  [
    uuid(CC2864E4-55BA-4057-8687-29153BE3E046),
    noncreatable,
    version(1.0)
  ]
  coclass HCTest
  {
     [default] interface ITest;
  };

};

推荐答案

这不需要修复,从类型库创建的互操作包装将是好的.可以使用ComTypes.IStream声明来实现托管代码来实现实现IStream或将其中一个作为参数的COM服务器.许多.NET框架类都可以.

This doesn't need fixing, the interop wrapper created from the type library will be fine. The ComTypes.IStream declaration is there to allow managed code to implement a COM server that implements an IStream or takes one as an argument. Lots of .NET framework classes do.

这篇关于如何在idl中声明IStream,以便Visual Studio将其映射到s.w.interop.comtypes?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 07:41