错误 C1189:#error:窗口。H 已包括在内。MFC 应用不得 #include < Windows.h>"**

error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>"**

本文关键字:lt #include gt Windows MFC 窗口 #error C1189 包括 错误 应用      更新时间:2023-10-16

我有一个使用stdafx.h作为预编译头的项目。这意味着所有的cpp文件必须包含#include "stdafx.h"作为第一个include。

然而,在A.h中,我需要包含"afxinet.h",但是编译器抱怨这个

"错误C1189: #error: WINDOWS.H已包含。MFC应用不能#include "windows.h"

"

这是因为"afxinet.h"在包含WINDOWS.H时报错,但"stdafx.h"确实包含了WINDOWS.H,并且作为A.cpp中的第一个包含。

这意味着我需要在"stdafx.h"前面包含"afxinet.h",但"stdafx.h"是预编译头文件,需要作为第一个包含…

我该如何解决这个困境?

如果你的项目使用MFC,那么你应该在stdafx.h中包含它的头文件,而不是使用windows.h(因为它将被MFC包含);如果包含windows.h,则不能使用MFC。afxinet.h是MFC的一部分,所以,我猜,你应该(1)用afxwin.h替换你的windows.h和"使用MFC"设置(2)不使用MFC包装WinInet,使用WinInet .h的函数