MFC Dll with COM Interface(带有 COM 接口的 MFC Dll)
问题描述
我对托管/非托管互操作性和 COM 概念非常陌生.
I am pretty new to managed/unmanaged interoperability and COM concepts.
我收到了使用 COM Interop 的建议,以便在 C# 中使用我现有的 MFC 代码.但对我来说问题是,我有一个不是有效 COM 组件的 MFC Dll.如何使这个 MFC DLL 具有可在 .NET 中使用的 COM 可访问接口?
I received a suggestion of using COM Interop, for using my existing MFC code in C#. But the problem for me is, i have a MFC Dll which is not a valid COM component. How can I make this MFC DLLs to have COM-accessible interfaces ready for use in .NET?
推荐答案
从线程 在 C# 中加载 MFC DLLWindows 应用程序
要从 C# 访问本机代码,您有几个选择.
To access native code from C# you have a few choices.
最直接的是,您可以使用 DllImportAttribute 以 C# 术语描述 DLL 的入口点,以便可以通过 P/Invoke 调用它们.它们看起来像 C# 程序的静态方法.
Most directly, you can use DllImportAttribute to describe your DLL's entry points in C# terms so that they can be called via P/Invoke. They'll look like static methods to your C# program.
不太直接,您可以创建一个托管 C++ 程序集,将您的 DLL 包装在一个或多个托管对象中.托管 C++ DLL 可以通过添加引用从 C# 访问(因为它是具有 .dll 扩展名的托管程序集),并且还应该能够通过使用 #include 来访问您的 MFC dll 以包含 MFC dll 的头文件.
Less directly, you can create a Managed C++ assembly that wraps your DLL in one or more managed objects. The Managed C++ DLL can be accessed from C# via Add Reference (because it is a managed assembly with a .dll extension) and should also be able to access your MFC dll by using #include to include the MFC dll's header file.
第三种选择是将您的 dll 转换为 COM 对象,以便您的 C# 程序可以通过这种方式访问它.
A third option would be to turn your dll into a COM object so that your C# program can access it that way.
这篇关于带有 COM 接口的 MFC Dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:带有 COM 接口的 MFC Dll
基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
