微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

COM interop,C#,Visual Studio 2010 – >嵌入互操作类型

我的C#程序通过Nco3(sapnco.dll)访问SAP.该程序还需要与Delphi一起使用.我的一些方法从sapnco.dll返回类型:

public void IRfcTable table(...) { ... }

在Delphi中,这种方法显示

function table(...): IUnkNown { ... }

我想这个IUnkNown是因为我的TLB不包含sapnco.dll.我在Visual Studio中尝试“嵌入Interop Types = true”,但是出现此错误

Error Interoptypen aus Assembly “C:\…” können nicht eingebettet werden,weil das ImportedFromTypeLibAttribute-Attribut oder das PrimaryInteropAssemblyAttribute-Attribut fehlt. c:…\sapnco.dll

(Interop Types Could not be embedded because some attributes are missing).

这是正确的方法吗?如果是这样,在哪里放置这些属性

@H_404_30@解决方法
sapnco.dll是一个.NET DLL,因此它不会暴露给COM,因此您无法在COM环境中直接使用此类型.您的问题的解决方案是创建一个库来将sapnco.dll包装在COM公开的类中:

举个例子:

[ComVisible(true)]
public interface IComrfcTable
{
    public void DoSomething();
}

[ComVisible(true)]
public class ComrfcTable
{
    private _rfcTable; // object to wrap
    public ComrfcTable(IRfcTable rfcTable)
    {
        _rfcTable = rfcTable
    }

    public void DoSomething()
    {
        _rfcTable.DoSomething();
    }
}

那么你的方法必须实现如下:

public IComrfcTable table(...) { ... }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐