c++ - 如何将使用 MFC 的类添加到 ATL 项目中?

标签 c++ dll mfc atl

我正在编写一个 .NET 分析器(一个 DLL)并且我正在使用 ATL。我想将一些使用 MFC 的类添加到我的项目中,但是我遇到了很多错误,但是这些类在 MFC 项目中运行良好。我尝试更改项目属性并设置 Use of MFC = Use MFC in a shared DLL 但它不起作用,我还尝试包括“afx.h”...

以下是我遇到的一些错误:

Error   214 error C2373: 'CString' : redefinition; different type modifiers iaparameters.cpp    31

Error   206 error C2653: 'CIAParameters' : is not a class or namespace name iaparameters.cpp    30

如有任何帮助,我们将不胜感激。

最佳答案

Baislcy 这应该是可能的,关于 this question .但根据我自己的经验,这样做有点棘手。您必须手动包含所用版本的 MFC header 。您也可以自定义您的 CWinApp 类以启用 MFC 类工厂(this is 为您生成的默认 MFC 支持。另外 this 可能有帮助)。

您还应该注意,对于 ATL 8,最重要的 MFC 和 ATL 类现在是 shared between both libraries .

如果这不起作用,最简单的方法是重新创建项目,选中MFC 支持 选项并重新导入您的代码。这就是我最终这样做的方式。

最后但同样重要的是,您还应该注意 ATL Internals指出您应该只在真正需要时才使用 MFC。如今,几乎所有强大的 MFC 助手也是 ATL 的一部分。这是书中的引述。前两个原因对 ATL 来说是一个很大的优势,最后一个更像是一个笑话:

  1. I can't live without CString (or CMap, CList, and so on) The MFC utility classes were built as a stopgap until the C++ standards committee defined a standard library. They've done it, so we can stop using the MFC versions. The classes string, map, list, and so on provided in the standard library are more flexible and more robust than their MFC equivalents. Moreover, CString is now a shared class between MFC and ATL, and thus is available in ATL projects without having to include the rest of MFC and link to the MFC library. Other MFC utility classes have also been made shared, including CPoint and CRect. And for those who liked the MFC collections classes, ATL now includes MFC style collections (CAtlMap, CAtlList, and so on).
  2. I can't live without the wizards. [...] The ATL wizards are arguably as extensive as the ones MFC provides.
  3. I already know MFC, and I can't learn anything new. [...]

ATL 为 STL 容器和类型提供了良好的支持。您应该考虑使用它们,而不是引用 MFC。

关于c++ - 如何将使用 MFC 的类添加到 ATL 项目中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15472883/

相关文章:

c# - 如何自动将 const wchar_t* 从 C DLL 转换为 C# 字符串

c++ - 从 dll 导入的类的线程安全

c++ - MFC DLL 的 GUI 线束?

c++ - 有没有比 SHGetPathFromIDList() 更好的方法将 itemidlist 转换为路径字符串?

c++ - VS 2008 中未捕获 HRESULT 异常

c++ - MFC编辑控件更新

c++ - 基类模板实例化取决于派生类构造函数参数类型

c++ - Qwt 简单图示例

c - 如何管理从 matlab coder 自动生成的 c 文件?

database - 如何检索表中的行数