从 C++ 创建 COM 对象?

发布于 2024-10-10 15:59:34 字数 116 浏览 0 评论 0原文

我想从 C++ 代码创建一个 dll 并在 C# 中使用它。有没有从 C++ 创建 COM 对象的解决方案?
我不想使用 System.Runtime.InteropServices。

非常感谢

I want to create a dll from a C++ code and the use it in C#. Is there a solution of creating COM object from C++ ?
I don't want to use System.Runtime.InteropServices.

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

眼眸印温柔 2024-10-17 15:59:34

当然,您可以使用 C++ 编写 COM+ 对象。 这是一个教程

Of course that you can write COM+ objects with C++. Here's a tutorial.

涙—继续流 2024-10-17 15:59:34

您可以直接编写COM(请参阅@Darin Dimitrov的回答),但您也可以使用ATL。我最喜欢的将 C++ 代码公开给 C# 的解决方案(尽管没有 COM)是使用 C++/ CLI

You can write COM directly (see @Darin Dimitrov's answer), but you can also use ATL. My favorite solution to expose C++ code to C# (without COM though) is to use C++/CLI.

猫瑾少女 2024-10-17 15:59:34

有3种方法可以解决这个问题。

1) 使用 C# 中的 PInvoke 调用本机方法。

2) 使用 C++-CLI 创建一个向 C# 公开本机功能的层。这是我推荐的性能明智的方法。

3) 将C++ dll编写为COM对象并从C#访问。需要 COM 知识,因此需要开发成本。

There are 3 ways to go about it.

1) Use PInvoke from C# to call into native methods.

2) Use C++-CLI to create a layer that exposes native functionality to C#. This is my recommended approach performance wise.

3) Write the C++ dll as a COM object and access from C#. Requires COM knowledge and hence developement cost.

在风中等你 2024-10-17 15:59:34

你可以使用ATL,它太简单了,你只需要注册dll即可。之后你就可以在所有c#程序中使用它

you can use ATL , it too easy and you just have to register the dll . after that you can use it in all c# programms

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文