For a static Win32 library, how can I detect that any of the "Use MFC" options is set?
对于静态Win32库,如何检测是否设置了“使用MFC”选项?
i.e.
即。
#ifdef ---BuildingForMFC---
....
#else
...
#endif
3 个解决方案
#1
10
I have always checked for the symbol _MFC_VER being defined.
我总是检查正在定义的符号_MFC_VER。
This is the version number of MFC being used 0x0700 = 7.0
这是使用0x0700 = 7.0的MFC版本号。
It is in the "Predefined Macros" in MSDN
它在MSDN中的“预定义宏”中
#2
3
I've check on Visual Studio 2013, in an original project targeting only Win32 console, so I've to add MFC support (without using of the Project Wizard) in a second time. Following are my findings:
我检查了Visual Studio 2013,在一个最初的项目中,我只针对Win32控制台,所以我必须第二次添加MFC支持(不使用项目向导)。以下是我的发现:
-
The macro _MFC_VER is defined in the afxver_.h, included by afx.h. So, if you don't include afx.h directly/indirectly in your .cpp file, you don't have the _MFC_VER macro defined. For example, including in a project a source .cpp that doesn't include the afx.h, the file will be compiled WITHOUT the definition of _MFC_VER macro. So it's useless for adapt the c++ code (an external library, for example) to detect usage of MFC library and optionally support the MFC library.
宏_MFC_VER在afxver_中定义。由afx.h h,包括。所以,如果你不包括afx的话。在.cpp文件中,没有定义_MFC_VER宏。例如,在一个项目中包含一个不包含afx的源。cpp。h,文件将在没有定义_MFC_VER宏的情况下编译。因此,修改c++代码(例如,外部库)以检测MFC库的使用情况并选择支持MFC库是毫无用处的。
-
If you manually turn on the use of MFC (Select the project in Solution Explorer, than right click, Configuration Properties -> General -> Use of MFC) you have two possibilities:
如果您手动启用MFC(在解决方案资源管理器中选择项目,比右键单击配置属性—>通用—>使用MFC),您有两种可能:
- A) select "Use MFC in a Shared DLL" option. This actually update the command line parameters adding the definition of _AFXDLL to the preprocessor macro list.
- A)选择“在共享DLL中使用MFC”选项。这实际上更新了命令行参数,将_AFXDLL的定义添加到预处理器宏列表中。
- B) select "Use MFC in a Static Library" options. This actually remove the _AFXDLL macro defined, but no macro definition is added, so nothing can told you if MFC is actually used.
- B)选择“在静态库中使用MFC”选项。这实际上删除了所定义的_AFXDLL宏,但是没有添加任何宏定义,因此没有任何东西可以告诉您是否实际使用了MFC。
So, during my test activity, only the mode A can be used effectively to understand if the MFC library is included or not in the project under building.
因此,在我的测试活动中,只有模式A可以有效地用于理解MFC库是否包含在正在构建的项目中。
I maintain a C++ cross-platform library that support many platforms (Mac OSx, WinX console, WinX MFC, iOS, Unix, Android) and enabling MFC with dynamic DLL is the only way to transparently detect the MFC presence. So for example:
我维护了一个c++跨平台库,该库支持许多平台(Mac OSx、WinX控制台、WinX MFC、iOS、Unix、Android),支持MFC的动态DLL是透明检测MFC存在的唯一方式。举个例子:
#if defined(_AFXDLL)
# include <afx.h>
#endif
Obviusly, you can add manually a macro definition (_AFX) in the project preprocessor list.
显然,您可以在项目预处理器列表中手动添加宏定义(_AFX)。
#3
0
The symbol _AFX
is typically defined for MFC projects.
符号_AFX通常为MFC项目定义。
#1
10
I have always checked for the symbol _MFC_VER being defined.
我总是检查正在定义的符号_MFC_VER。
This is the version number of MFC being used 0x0700 = 7.0
这是使用0x0700 = 7.0的MFC版本号。
It is in the "Predefined Macros" in MSDN
它在MSDN中的“预定义宏”中
#2
3
I've check on Visual Studio 2013, in an original project targeting only Win32 console, so I've to add MFC support (without using of the Project Wizard) in a second time. Following are my findings:
我检查了Visual Studio 2013,在一个最初的项目中,我只针对Win32控制台,所以我必须第二次添加MFC支持(不使用项目向导)。以下是我的发现:
-
The macro _MFC_VER is defined in the afxver_.h, included by afx.h. So, if you don't include afx.h directly/indirectly in your .cpp file, you don't have the _MFC_VER macro defined. For example, including in a project a source .cpp that doesn't include the afx.h, the file will be compiled WITHOUT the definition of _MFC_VER macro. So it's useless for adapt the c++ code (an external library, for example) to detect usage of MFC library and optionally support the MFC library.
宏_MFC_VER在afxver_中定义。由afx.h h,包括。所以,如果你不包括afx的话。在.cpp文件中,没有定义_MFC_VER宏。例如,在一个项目中包含一个不包含afx的源。cpp。h,文件将在没有定义_MFC_VER宏的情况下编译。因此,修改c++代码(例如,外部库)以检测MFC库的使用情况并选择支持MFC库是毫无用处的。
-
If you manually turn on the use of MFC (Select the project in Solution Explorer, than right click, Configuration Properties -> General -> Use of MFC) you have two possibilities:
如果您手动启用MFC(在解决方案资源管理器中选择项目,比右键单击配置属性—>通用—>使用MFC),您有两种可能:
- A) select "Use MFC in a Shared DLL" option. This actually update the command line parameters adding the definition of _AFXDLL to the preprocessor macro list.
- A)选择“在共享DLL中使用MFC”选项。这实际上更新了命令行参数,将_AFXDLL的定义添加到预处理器宏列表中。
- B) select "Use MFC in a Static Library" options. This actually remove the _AFXDLL macro defined, but no macro definition is added, so nothing can told you if MFC is actually used.
- B)选择“在静态库中使用MFC”选项。这实际上删除了所定义的_AFXDLL宏,但是没有添加任何宏定义,因此没有任何东西可以告诉您是否实际使用了MFC。
So, during my test activity, only the mode A can be used effectively to understand if the MFC library is included or not in the project under building.
因此,在我的测试活动中,只有模式A可以有效地用于理解MFC库是否包含在正在构建的项目中。
I maintain a C++ cross-platform library that support many platforms (Mac OSx, WinX console, WinX MFC, iOS, Unix, Android) and enabling MFC with dynamic DLL is the only way to transparently detect the MFC presence. So for example:
我维护了一个c++跨平台库,该库支持许多平台(Mac OSx、WinX控制台、WinX MFC、iOS、Unix、Android),支持MFC的动态DLL是透明检测MFC存在的唯一方式。举个例子:
#if defined(_AFXDLL)
# include <afx.h>
#endif
Obviusly, you can add manually a macro definition (_AFX) in the project preprocessor list.
显然,您可以在项目预处理器列表中手动添加宏定义(_AFX)。
#3
0
The symbol _AFX
is typically defined for MFC projects.
符号_AFX通常为MFC项目定义。