环境:Win7 x64,VS2015

描述:开发项目时,添加了stdafx.h,编译报错

C++ error C1189:WINDOWS.H already included.

分析

首先找到afxv_w32.h是怎么被调用的?

查找发现头文件包含顺序:stdafx.h  -> afxwin.h -> afx.h -> afxver_.h -> afxv_w32.h

打开 afxv_w32.h:

C++ error C1189:WINDOWS.H already included.

也就是说,如果定义了  _WINDOWS_ 就会报错。

而 _WINDOWS_  是在Window.h中定义的

C++ error C1189:WINDOWS.H already included.

结论:在stdafx.h 之前调用 #include <Windows.h>就会报错

解决办法应将stdafx.h 放到Windows.h前面,这是编译器编译顺序的问题!

相关文章: