【问题标题】:How to implement a SAFEARRAY(long) parameter?如何实现 SAFEARRAY(long) 参数?
【发布时间】:2013-03-18 21:22:02
【问题描述】:

我目前在一个接口中有一个 C# 方法,在查看时具有以下参数 ITypeLib

HRESULT _stdcall SomeMethod ([in] Is_interface* inst, 
           [in] SAFEARRAY(long) bid);

上述方法在一个接口中,并在 C# 中定义。生成类型库后,我试图在 C++ 中创建该接口的实现。但是我无法弄清楚

所需的类型
[in] SAFEARRAY(long) bid

我目前正在尝试这样的事情

virtual HRESULT STDMETHODCALLTYPE SomeMethod (Is_interface* inst, CComSafeArray<long> bid);

对于实现 C# 接口的类,任何关于 [in] SAFEARRAY(long) bid 的等价物的建议。

【问题讨论】:

  • 我猜是LPSAFEARRAYLPSAFEARRAY*。您也可以为此使用变体。

标签: c# c++ com safearray


【解决方案1】:

SAFEARRAY 是数组的默认互操作类型。只需一个普通的 int[] 就可以了。例如:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComVisible(true)]
public interface IFoo {
    void Method(object inst, int[] array);
}

生成此类型库条目,通过 OleView.exe、File + View TypeLib 命令获得:

[
  odl,
  uuid(2380B019-1E69-386E-BB6E-ECEF45257086),
  version(1.0),
  dual,
  oleautomation,
  custom(0F21F359-AB84-41E8-9A78-36D110E6D2F9, "ClassLibrary1.IFoo")    

]
interface IFoo : IDispatch {
    [id(0x60020000)]
    HRESULT Method(
                    [in] VARIANT inst, 
                    [in] SAFEARRAY(long) array);
};

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 2018-05-10
    • 1970-01-01
    • 2014-05-14
    • 2012-08-03
    • 1970-01-01
    • 2013-03-07
    • 2019-01-09
    • 1970-01-01
    相关资源
    最近更新 更多