windows.h and MFC

后端 未结 2 811
时光说笑
时光说笑 2021-01-02 17:18

Why can\'t I include windows.h in afx(MFC) projects?

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 17:52

    Typically, MFC application code includes afx.h or afxwin.h (the latter includes former). First two lines of windows.h are

    #ifndef _WINDOWS_
    #define _WINDOWS_
    

    which means that _WINDOWS_ becomes defined if this header is included. Afx.h includes afxver_.h and this header includes afxv_w32.h which contains following code:

    #ifdef _WINDOWS_
        #error WINDOWS.H already included. MFC apps must not #include 
    #endif
    ...
    #include 
    

    So, if you include windows.h before MFC headers, you'll get this error generated in compile time and, as you can see, if you include afxwin.h you don't need to include windows.h yourself - it will already be included by afxv_w32.h.

提交回复
热议问题