【问题标题】:Embed native dll or .NET assembly into COM将本机 dll 或 .NET 程序集嵌入 COM
【发布时间】:2014-12-05 03:58:09
【问题描述】:

我有一个 .NET 库,我想用 COM 包装它以从 C++ 调用它的函数。幸运的是,这个库是开源的,如果我在这个项目中添加 COM 可见类 - 它可以工作:

[Guid("38F752CC-20F1-4729-B1E3-EE0AAD145052")]
public interface IQRCodeUI
{
    string GetDecodedString(string encodedString);
}

[Guid("D4CFCDFA-6718-494D-A23F-EBC0F9550377")]
public class QRCodeUI : IQRCodeUI
{
    public string GetDecodedString(string encodedString)
    {
        return decoder.decode(encodedString);
    }
}

decoder 就是这个库中的一个类。

但是如果我要编译程序集怎么办?我尝试创建类库 (COM) 并将 .NET 库作为嵌入式资源添加到它。没有结果!在编译期间它说类似cannot register assembly "path\name". Cannot load file or assembly "nameOfAssembly" or its dependency. Cannot find the file.Apologise,我无法提供错误的原始文本,因为我有MSVS,它的语言与英语不同。有可能解决这个问题吗?

【问题讨论】:

  • @Dan,问题是如何通过 COM 在 C++ 中使用已编译的 .NET 程序集的功能?

标签: c# c++ .net com .net-assembly


【解决方案1】:

如果您的任务是通过 COM 从 C++ 调用 .NET 库,为什么要将 .NET 库作为嵌入式资源添加到某个新的 COM 类库中?

只需使现有的第三方程序集 COM 可见,并从 C++、VB6 等中调用它。

互联网上有许多关于如何使 .NET 程序集 COM 可见的文档。我记得,其中没有一个包含将 .NET 程序集嵌入 COM 类程序集的建议。

开始: Best Practice in Writing a COM-Visible Assembly (C#)

【讨论】:

  • 正如我上面提到的,我的问题是如何通过COM在C++中使用已编译的.NET程序集的功能?
猜你喜欢
  • 2011-07-27
  • 1970-01-01
  • 1970-01-01
  • 2014-02-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-31
相关资源
最近更新 更多