How to define "Use MFC" in the preprocessor

For the Win32 static library, how can I determine if any of the "Use MFC" options is set?

i.e.

#ifdef ---BuildingForMFC--- .... #else ... #endif 
+7
c ++ mfc visual-c ++ - 2008
source share
3 answers

I have always verified that the _MFC_VER symbol is indicated.

This is the version number of the used MFC 0x0700 = 7.0

It is located in the "Predefined Macros" section on MSDN.

+10
source share

I checked Visual Studio 2013 in the original project focused only on the Win32 console, so I have to add MFC support (without using the Project Wizard) a second time. Below are my findings:

  • The _MFC_VER macro is defined in afxver_.h included by afx.h. So, if you do not include afx.h directly / indirectly in your .cpp file, you do not have the _MFC_VER macro. For example, by including a .cpp source in the project that does not include afx.h, the file will be compiled WITHOUT the _MFC_VER macro definition. Therefore, it is useless to adapt C ++ code (for example, an external library) to detect the use of the MFC library and, if necessary, support for the MFC library.

  • If you manually enable the use of MFC (select the project in the solution explorer than right-click Configuration Properties → General → Use MFC), you have two options:

    • A) select "Use MFC in the shared DLL". This actually updates the command line options by adding the _AFXDLL definition to the list of preprocessor macros.
    • B) select the option "Use MFC in the static library". This actually removes the _AFXDLL macro, but no macro definition is added, so nothing can tell you if MFC is actually used.

Thus, during my test activity, only mode A can be effectively used to understand whether the MFC library is included or not in the project under the building.

I support the cross-platform C ++ library that supports many platforms (Mac OSx, WinX console, WinX MFC, iOS, Unix, Android) and allows MFC with a dynamic DLL - the only way to transparently detect the presence of MFC. For example:

 #if defined(_AFXDLL) # include <afx.h> #endif 

Obviusly, you can manually add a macro definition (_AFX) to the project preprocessor list.

+3
source share

The _AFX symbol _AFX usually defined for MFC projects.

0
source share

All Articles