windows.h and MFC

不羁的心 提交于 2019-12-18 16:26:11

问题


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


回答1:


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 <windows.h>
#endif
...
#include <windows.h>

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.




回答2:


Because in MFC you are not supposed to use it directly. AFAIR you should include afx.h instead, which in turn indirectly includes windows.h the proper way.



来源:https://stackoverflow.com/questions/5026799/windows-h-and-mfc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!