VS2019 Windows.h / MFC conflict

I've been working on a static library. Everything was fine until a couple of days ago. Then I started getting the following error message:

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\atlmfc\include\afxv_w32.h(16,1): fatal error C1189: #error: WINDOWS.H already included. MFC apps must not #include <Windows.h>

I have only one .cpp file that requires <windows.h> for access to the console routines. For some reason VS thinks I'm using MFC. As far as I know, I'm not.
I can find only one setting in the project property pages related to MFC.

USE MFC: { Use Standard Windows Libraries | Use MFC in a Static Library | Use MFC in a Shared DLL | <inherit from parent or project defaults> }

I've tried all four settings, all four result in an error.

Edit to add:
USE STANDARD LIBRARIES, USE SHARED DLL amd INHERIT PROJECT DEFAULTS all result in the above message.
USE MFC IN STATIC LIBRARY results in

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\atlmfc\include\afxver_.h(77,1): fatal error C1189: #error: Please use the /MD switch for _AFXDLL builds


I've tried creating the project from scratch and still get the same errors.
Last edited on
If MFC isn't used, that option should be set to 'Use Standard Windows Libraries'.

What #includes are you using?
That's what I thought too.

I have a CONSOLE class that serves as a wrapper for the Windows API console calls.
Other than my own includes and the needed C++ libraries, I'm including <windows.h> in the projlib.h file which includes console.h because console.h needs HANDLE.

Edit:
I've narrowed it down to my projlib.h header. I have a couple of simple shape classes that only include their own headers and they compile fine. If I use my projlib.h header, they fail with the one of the above messages.
Last edited on
Hi AbstractionAnon

Maybe this is a stupid idea but i always put <windows.h> in both .hpp and .cpp files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

// in .hpp file

#ifndef YOUR_FILE_HPP
#define YOUR_FILE_HPP

#include <windows.h>

#endif


// in .cpp file

#include <windows.h>

Thanks for the suggestion. <windows.h> has it's own include guards so the second #include will have no effect.

I went back to your turboscreen\main.cpp example and that compiles just fine. When I look at the property pages for that project there is no USE MFC option.

So something in my code is triggering the USE MFC option which seems to be the problem.

Window message system is from win32 or MFC ?

VC++ win32 project, win32 console application or MFC project ?

Go to project properties.

Maybe your project file is corrupted.

afxv_w32.h has a <windows.h> in it ?

i saw this in a forum

There is #include "windows.h" somewhere in your stdafx.h. Replace it with afxwin.h, include afxinet.h after that and set "this project uses MFC" in project settings; then try to build.



found something in this link ...

https://www.codeproject.com/questions/562146/fatalpluserrorplusc1189-3aplus-23errorplus-3aplusp
Last edited on
@forgottencoder - Thanks for the link. That was helpful. I replaced the #include of <windows.h> with the following four lines and everything now compiles.
1
2
3
4
#define _AFXDLL
#include <SDKDDKVer.h>
#include <afx.h>
#include <afxwin.h>    

Now I'm getting lots of linker errors which tells me I have the wrong libraries linked.

Edit: Found the correct libraries: Multi-threaded debug DLL
Program now runs.
Last edited on
Topic archived. No new replies allowed.