[英]windows.h and MFC
为什么我不能在afx(MFC)项目中包含windows.h?
Typically, MFC application code includes afx.h
or afxwin.h
(the latter includes former). 通常,MFC应用程序代码包括
afx.h
或afxwin.h
(后者包括前者)。 First two lines of windows.h
are 前两行是
windows.h
#ifndef _WINDOWS_
#define _WINDOWS_
which means that _WINDOWS_
becomes defined if this header is included. 这意味着如果包含此标头,
_WINDOWS_
将被定义。 Afx.h
includes afxver_.h
and this header includes afxv_w32.h
which contains following code: Afx.h
包含afxver_.h
,该头文件包含afxv_w32.h
,其中包含以下代码:
#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
. 因此,如果在MFC头之前包含
windows.h
,则会在编译时生成此错误,如您所见,如果包含afxwin.h
,则不需要自己包含windows.h
- 它已经存在包含在afxv_w32.h
。
Because in MFC you are not supposed to use it directly. 因为在MFC中你不应该直接使用它。 AFAIR you should include afx.h instead, which in turn indirectly includes windows.h the proper way.
AFAIR你应该包括afx.h,反过来间接包括windows.h正确的方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.