29
votes

While migrating an old C++ project from Visual Studio 6 up to Visual Studio 2012, we came across an odd set of warnings from inside the standard Microsoft platform headers:

  • warning C4005: '__useHeader' : macro redefinition
  • warning C4005: '__on_failure' : macro redefinition

An online search only found a few other people running into this error. In some cases, it was people trying to use VS2012 to compile legacy DirectX code - which I am not doing. In other cases, it was people trying to use VS2012 to target Windows XP (using the new option from Update 1) - which I am doing.

The DirectX question was answered that the warning will always be there to tell you that you're compiling with an out-of-date (pre-Win8) version of DirectX, and you'll just have to live with it.

The Windows XP question was not answered. Other people simply said that they couldn't reproduce the problem.

I reproduced it, and found the cause, which I am writing up here to help anybody else who encounters this.

11

11 Answers

21
votes

Go into the project properties, and find the "Preprocessor Definitions" field.

In addition to the default and added definition constants, you should see a macro:

%(PreprocessorDefinitions)

This macro apparently brings in some additional compiler-provided preprocessor definitions. I am not sure what version of Visual Studio introduced this macro, but it was not there in Visual Studio 6.

In Visual Studio 2012, this macro is required to be present in your project's Preprocessor Definitions field. It may also be required in earlier versions of Visual Studio, but I have not tested these.

If this macro is missing, you will see the error messages as shown above.

13
votes

UPDATE:

See Edmund's answer to this same question first -- give that a try. If it works, great! If not... try the following:

ORIGINAL:

Use the workaround mentioned on the "Workarounds" tab of this web page:

http://connect.microsoft.com/VisualStudio/feedback/details/789965/resource-editor-warning-rc4005-on-toolset-visual-studio-2012-windows-xp-v110-xp

Namely, add:

#define _USING_V110_SDK71_ 1

...directly in the .rc file before it includes anything that would include the system headers that cause this warning.

11
votes

Haven't found a solution to this published anywhere online, so here's what worked for me.

I'm building a project with 110_xp tools

I get these warnings ...

c:\program files (x86)\microsoft sdks\windows\v7.1a\include\sal_supp.h(57): warning C4005: '__useHeader' : macro redefinition
          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2872) : see previous definition of '__useHeader'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\specstrings_supp.h(77): warning C4005: '__on_failure' : macro redefinition
          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2882) : see previous definition of '__on_failure'

Clearly an inconsistency between the VC 11 headers and 7.1a sdk headers.

In my stdafx.cpp I did this ...

#define _USING_V110_SDK71_

#include "stdafx.h"

... the build problem has gone away.

6
votes

This is a resource compiler warning. The solution is easy. Right click on the .rc file in the solution explorer and choose Properties. Now go to Resources > General > Preprocessor Definitions, and add

%(PreprocessorDefinitions)
4
votes

Adding #define _USING_V110_SDK71_ in Stdafx.cpp or Stdafx.h would not work if your cpp files do not have precompiled headers.

To solve this problem, the following works.

Right-click project in Solution Explorer* → PropertiesC/C++PreprocessorPreprocessor definitionedit → Add _USING_V110_SDK71_

4
votes

For me another solution worked.

In project PropertiesConfiguration propertiesC/C++General, I changed the field Addition Include Directories path to SDK with this macro:

$(WindowsSDK_IncludePath)

Before that, this field had the path to my SDK v7.1, and I had the same warnings.

2
votes

It is still simpler.

Just check the checkbox "Inherit from parent or project defaults" in Configuration PropertiesC/C++Preprocessor / Preprocessor DefinitionsEdit.

1
votes

I had this problem in some projects that originated with VC++ 2003 and have been incrementally upgraded over the years. I found that while the project settings had %(PreprocessorDefinitions) in Preprocessor Definitions, a few of the .cpp files didn't (The oldest ones). After changing them to "Inherit from parent or project defaults" it got rid of the warnings.

1
votes

For me this happened with Visual Studio 2017 (both fresh and repaired installation). Obviously the Windows 7.1 SDK had been installed before VS2017 and had been integrated into a Visual Studio 2005 installation.

In my case the two files:

  • %LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props
  • %LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props

contained references to the include directories and libraries of the Windows 7.1 SDK. Removing these references did the job.

Keep in mind that every single C++ project for Win32 and x64 respectively inherits from these property sheets.

0
votes

Although this answer is for VS10, it's of interest as might provide some clues as to what's going on viz the VC++ directories macros: The warning appeared when these statements were added in the header file of a project, MyApp:

#ifndef NTDDI_WINXPSP3
#define NTDDI_WINXPSP3 0x05010300
#endif 
#ifndef NTDDI_VISTA
#define NTDDI_VISTA 0x06000000
#endif 
#ifndef NTDDI_VISTASP1
#define NTDDI_VISTASP1 0x06000100
#endif 
#ifndef NTDDI_WS08
#define NTDDI_WS08 0x06000100
#endif 

Warnings like the following popped up for all but the XPSP3 def.:

Warning RC4005: 'NTDDI_VISTASP1' : redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sdkddkver.h.., MyApp

MyApp was a WinDebug 32 build, noting Windows7.1SDK appeared in the X64 section of the proj file:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<PlatformToolset>Windows7.1SDK</PlatformToolset>

The inherited value for Preprocessor Definitions was _VC80_UPGRADE=0x0600. Having used the SDK toolset prior to reverting to V100, the SDK libraries were found as inherited_from in Include directories and Library Directories in the VC++ Directories section, as noted here.
Looks like the warning is generated as a result of a combination of upgrading, migration, or toolset changes.

Edit: An unrelated issue in VS2017 (MBCS) is opting to use

LoadCursorW(nullptr, IDC_ARROW)

instead of the default LoadCursorA(...) in a WNDCLASSEXW structure. A possible solution is to redefine like so:

 #define IDC_ARROW           MAKEINTRESOURCEW(32512)

Here the warning can be suppressed by using the #undef procedure prior to the #define:

#ifdef IDC_ARROW
#undef IDC_ARROW
#endif
#define IDC_ARROW           MAKEINTRESOURCEW(32512)
0
votes

I know this is old question, but... "sometimes they come back" :)

Faced same warnings after install VS 2012 Express at fresh OS. After some investigation i decided to compare my current Program Files (x86)\Microsoft Visual Studio 11.0\VC\include folder with the same folder with VS 2012 Update 4. Here is comparison result: enter image description here

And sal.h diffs: enter image description here

So simple copying __useHeader's checks fixed all warnings.