gpt4 book ai didi

c# - 带 COM 接口(interface)的 MFC Dll

转载 作者:行者123 更新时间:2023-11-30 21:21:26 24 4
gpt4 key购买 nike

我对托管/非托管互操作性和 COM 概念还很陌生。

我收到了使用 COM Interop 的建议,以便在 C# 中使用我现有的 MFC 代码。但对我来说问题是,我有一个 MFC Dll,它不是有效的 COM 组件。如何使此 MFC DLL 具有可在 .NET 中使用的 COM 可访问接口(interface)?

最佳答案

来自线程 Loading MFC DLL in C# Windows Application

To access native code from C# you have a few choices.

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.

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.

A third option would be to turn your dll into a COM object so that your C# program can access it that way.

关于c# - 带 COM 接口(interface)的 MFC Dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2719968/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com