Reputation: 41096
For a static Win32 library, how can I detect that any of the "Use MFC" options is set?
i.e.
#ifdef ---BuildingForMFC---
....
#else
...
#endif
Upvotes: 13
Views: 5010
Reputation: 706
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:
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.
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:
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.
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:
#if defined(_AFXDLL)
# include <afx.h>
#endif
Obviusly, you can add manually a macro definition (_AFX) in the project preprocessor list.
Upvotes: 5
Reputation: 905
I have always checked for the symbol _MFC_VER being defined.
This is the version number of MFC being used 0x0700 = 7.0
It is in the "Predefined Macros" in MSDN
Upvotes: 14