COM互操作和propput/propputref [英] COM Interop and propput/propputref

查看:86
本文介绍了COM互操作和propput/propputref的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我想创建一个支持以下COM接口(IDL声明)的.NET对象-我必须在此处确保二进制兼容性:

I want to create a .NET object that supports the following COM interface (IDL declarations) - I MUST insure binary compatibility here :

interface IMyInterface
{
  [id(0x000000ff), propputref]
  HRESULT SomeProperty([in] IDispatch* pvar);
  
  [id(0x000000ff), propput]
  HRESULT SomeProperty([in] VARIANT pvar);
  
  [id(0x000000ff), propget]
  HRESULT SomeProperty([out, retval] VARIANT* pvar);
}

我尝试了不同的解决方案,但是没有一个解决我的问题...

I try different solutions, but none of them solves my problem...

  [ComVisible(true)]
  [Guid("2E913C9C-3C27-49b9-B239-BD026CC04DCE")]
  public interface IPutGet
  {
    [DispId(0xff)]
    object SomeProperty
    {
      [param: In, MarshalAs(UnmanagedType.Struct)]
      [DispId(0xff)]
      set;

      [DispId(0xff)]
      get;
    }
  }

  [ComVisible(true)]
  [Guid("0878F7D5-90E8-4729-89D4-66011F9DFEE4")]
  public interface IPropPutGet
  {
    [DispId(0xff)]
    object SomeProperty
    {
      [param: In, MarshalAs(UnmanagedType.IDispatch)]
      [DispId(0xff)]
      set;

      [DispId(0xff)]
      get;
    }
  }

在生成的TLB中给出以下内容:

which gives the following in the generated TLB :

  [
   odl,
   uuid(2E913C9C-3C27-49B9-B239-BD026CC04DCE),
   version(1.0),
   dual,
   oleautomation,
   custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ComTests.IPutGet")  

  ]
  interface IPutGet : IDispatch {
    [id(0x000000ff), propputref]
    HRESULT SomeProperty([in] VARIANT pRetVal);
    [id(0x000000ff), propget]
    HRESULT SomeProperty([out, retval] VARIANT* pRetVal);
  };

  [
   odl,
   uuid(0878F7D5-90E8-4729-89D4-66011F9DFEE4),
   version(1.0),
   dual,
   oleautomation,
   custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ComTests.IPropPutGet")  

  ]
  interface IPropPutGet : IDispatch {
    [id(0x000000ff), propputref]
    HRESULT SomeProperty([in] IDispatch* pRetVal);
    [id(0x000000ff), propget]
    HRESULT SomeProperty([out, retval] VARIANT* pRetVal);
  };

我找不到任何方式来生成支撑". ;具有所有三个propputref/propput/propget似乎更加复杂...:-/

我在某些论坛上唯一能找到的答案是手动"构建正确的TLB,但是首先-我觉得这很丑陋-我也想知道它在所有情况下是否都有效,即直接接口调用和/或通过IDispatch接口调用.

I couldn't find any way to generate a "propput" ; having all three propputref/propput/propget seems even more complicated ... :-/

The only answer I could find on some forums was to be build the correct TLB "manually", but first - I find this quite ugly - and I'm also wondering if it's working in all case, i.e. direct interface call and/or call through IDispatch interface.

有什么想法吗?

预先感谢

Ludovic.

推荐答案

 

生成.NET的等效接口签名从COM接口,您可以将COM接口构建到COM dll;然后使用 针对COM dll tlbimp.exe 生成一个互操作程序集,您可以在其中找到相应的接口签名:

To generate an equivalent interface signature of .NET from a COM interface, you may build the COM interface into a COM dll; and then use tlbimp.exe against the COM dll to generate an interop assembly, in which you can find corresponding interface signature:

MethodImpl ( MethodImplOptions .InternalCall,MethodCodeType = MethodCodeType .运行时), DispId (0xff)]

        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0xff)]

无效 let_SomeProperty([中, MarshalAs ( UnmanagedType .Struct)] 对象 pvar);

        void let_SomeProperty([In, MarshalAs(UnmanagedType.Struct)] object pvar);

DispId (0xff)]

        [DispId(0xff)]

对象 SomeProperty

        object SomeProperty

        {

返回: MarshalAs ( UnmanagedType .Struct)]

            [return: MarshalAs(UnmanagedType.Struct)]

MethodImpl ( MethodImplOptions .InternalCall,MethodCodeType = MethodCodeType .运行时), DispId (0xff)]

            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0xff)]

获取

            get;

参数:中, MarshalAs ( UnmanagedType .IDispatch)]

            [param: In, MarshalAs(UnmanagedType.IDispatch)]

MethodImpl ( MethodImplOptions .InternalCall,MethodCodeType = MethodCodeType .运行时), DispId (0xff)]

            [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId(0xff)]

设置

            set;

        }


这篇关于COM互操作和propput/propputref的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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