NTDDI_VERSION setting conflicts with _WIN32_WINNT setting - c++

With VS2010 I have this error:
error C1189: #error : NTDDI_VERSION setting conflicts with _WIN32_WINNT setting
in StdAfx.h is use:
#define _WIN32_WINNT 0x0502
and in my other source my.cpp i use:
#define NTDDI_VERSION 0x06000000
How I can solve that?

#define NTDDI_VERSION 0x06000000
That is Vista.
#define _WIN32_WINNT 0x0502
That is Server 2003.
And so these versions are indeed conflicting. If you want to support Vista and up you'll need:
#define NTDDI_VERSION 0x06000000
#define _WIN32_WINNT 0x0600
If you want Server 2003 and up then you use:
#define NTDDI_VERSION 0x05020000
#define _WIN32_WINNT 0x0502
Note that the NTDDI_VERSION define can also specify service packs. So if you want Vista SP1 and up then you use:
#define NTDDI_VERSION 0x06000100
#define _WIN32_WINNT 0x0600
As a general rule you want to set these defines to the value corresponding to the minimum version that you wish to support.
Rather than using these magic constants, you should write, for example:
#define NTDDI_VERSION NTDDI_VISTA
#define _WIN32_WINNT _WIN32_WINNT_VISTA
For more details refer to MSDN: Using the Windows Headers.

NTDDI_VERSION 0x06000000 is Windows Vista, so you need #define _WIN32_WINNT 0x0600.
MSDN has the details you need right here.

Related

Windows SDK control available functions

Function AddDllDirectory was added to Windows 7 in one of the updates.
I'm using Windows 10 SDK headers in my c++ application. Is it possible to configure them to show only functions available in first Windows 7 version (without any updates) ?
I read about defines of:
WINVER, _WIN32_WINNT
I tried to set them to:
#define _WIN32_WINNT 0x601
#define NTDDI_VERSION 0x06010000
or even:
#define _WIN32_WINNT 0x600
#define NTDDI_VERSION 0x06000000
, but it doesn't work.
The NTDDI_VERSION macro uses a 32-bit number that includes service pack information. The older defines (WINVER, _WIN32_WINNT, _WIN32_WINDOWS, and _WIN32_IE) is just a 16-bit number, typically in hex: 0xaabb where aa is the Windows major version and bb is the minor version.
The correct value for Windows 7 is therefore 0x0601 for these defines and 0x06010000 is just for NTDDI_VERSION. The SdkDdkver.h header also provides macros like _WIN32_WINNT_WIN7 and NTDDI_WIN7 where the version numbers are listed for you.

'CheckTokenMembership' to check for Admin Rights C++

i'm trying to use the CheckTokenMembership function, i copied the example piece of code on Microsofts website ( https://msdn.microsoft.com/pt-br/library/windows/desktop/aa376389(v=vs.85).aspx ), but i just can't get it to work!
I get "error: 'CheckTokenMembership' was not declared in this scope" (on CodeBlocks) no matter what i do.
I am including Windows.h and even Winbase.h as the website says. Does anyone have any idea on how to fix this?
Before including windows.h you need to specify the minimum version of Windows your application will support. The idea here is that the build will fail if you use an API function that isn't available in the specified Windows version.
You can do this by defining the _WIN32_WINNT macro, e.g., for Windows 7:
#define _WIN32_WINNT _WIN32_WINNT_WIN7
If you need to be more specific you can also define the NTDDI_VERSION macro, e.g., for Windows 10 version 1607:
#define _WIN32_WINNT _WIN32_WINNT_WIN10
#define NTDDI_VERSION NTDDI_WIN10_RS1
The documentation tends to lag behind, but you can find the definitions in sdkddkver.h in the SDK.
Addendum:
In some cases, e.g., if using an old or third-party version of the SDK, the named constants may not work and you will have to resort to magic values, e.g., the examples above would become
#define _WIN32_WINNT 0x0601
and
#define _WIN32_WINNT 0x0A00
#define NTDDI_VERSION 0x0A000002
You can look these up by obtaining a recent version of sdkddkver.h from Microsoft or you could try the search engine of your choice. :-)

identifier "PLVGROUP" is undefined afxcmn.h

I have a Visual Studio 2015 project which uses the afxcmn header and is having a lot of "is undefined" errors.
I read in the documentation those data types are included in commctrl.h which is already included in the Visual Studio project as external dependency.
// Adds a group to the control.
AFX_ANSI_DEPRECATED int InsertGroup(_In_ int index, _In_ PLVGROUP pgrp);
// Sets information about the specified group (by ID) in the control.
AFX_ANSI_DEPRECATED int SetGroupInfo(_In_ int iGroupId, _In_ PLVGROUP pGroup);
// Retrieves information for the specified group in the control.
AFX_ANSI_DEPRECATED int GetGroupInfo(_In_ int iGroupId, _Out_ PLVGROUP pgrp) const;
That is some code example of the afxcmn.h which gives those errors.
I dont know if I have to configure something else in the project to include the commctrl header
yes, PLVGROUP is defined in commctrl.h, but it depends on WINVER
#if (NTDDI_VERSION >= NTDDI_WINXP)
that means WINVER >= 501, see:
error-Direktive: MFC does not support WINVER less than 0x0501. Please change the definition of WINVER in your project properties or precompiled header.
So I had to change my stdafx.h
//#define WINVER 0x0500
#define WINVER NTDDI_WINXP //0x05010000
They are IntelliSense errors generated by Visual Studio 2015.
My environment is Windows 10 1903/VS2017
I don't know exactly why, but this solves the problem for me:
FYI, this is the original stdafx.h in my project that produce the error in the question:
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#endif
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0400 // Change this to the appropriate value to target IE 5.0 or later.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
......
after adding these two lines bellow "#pragma once" the problem is solved:
#define WINVER 0x0603
#define _WIN32_WINNT 0x0603
Only adding the first line still produce those errors.

error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0500. Value 0x0501 or higher is recommended

I create MFC project in VS2010(windows xp). And i take this error:
error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0500. Value 0x0501 or higher is recommended.
if I added in afxcomctl32.h: #define _WIN32_WINNT 0x0501, i take 60+ errors.
In project i dont added anything. Use such as Visual Studio created.
What i need to do with this?
afxcomctl32.h is a wrong place I think, to fix this problem make your stdafx.h looking like this:
// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0501 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target Windows 98 and Windows 2000 or later.
#endif
#ifndef _WIN32_WINDOWS // Allow use of features specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0501 // Change this to the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE // Allow use of features specific to IE 4.0 or later.
#define _WIN32_IE 0x0500 // Change this to the appropriate value to target IE 5.0 or later.
#endif
Try adding this to the TOP of your StdAfx.h file:
#include <sdkddkver.h>
In my application, I'm defining
_WIN32_WINNT=_WIN32_WINNT_WINXP
At first I had the same problem. I discovered that because when you use MFC, you're not allowed to include windows.h, _WIN32_WINNT_WINXP is never defined and so _WIN32_WINNT didn't have a valid value. By including the header that windows.h uses to define those values (sdkddkver.h), suddenly everything works!
Blech. I hate programming for Windows.
You don't need to modify afxcomctl32.h. You just need to include Windows.h before this file.
Should work.
I solved my problem. The fact was that the file atmcore.h was different from the standart in VS2010.

Error with RegOpenKeyEx()

I'm using Qt with mingw to write a program that changes the registry, but when I call :
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\DefaultProductKey",
0,
KEY_ALL_ACCESS|KEY_WOW64_64KEY,
&key);
Qt return :
`KEY_WOW64_64KEY' undeclared (first use in this function)
I had add "#include <windows.h>" but it still doesn't work.
I've find this post Error with RegOpenKeyEx, it's the same probleme than me, and the answer looks good.
But i'm not using windows xp i'm using 7(64bits).
So I trided to put in targetver.h :
#ifndef _WIN32_WINNT_WIN7
#define _WIN32_WINNT_WIN7 (0x0601)
#endif /* _WIN32_WINNT_WIN7 */
And it's still doesn't work ... :(
What can i do ? :(
Thanks :)
(sorry for my bad english)
You have to define the _WIN32_WINNT (not _WIN32_WINNT_WIN7) before including the windows.h header:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT (0x0601)
#endif /* _WIN32_WINNT */
#include <windows.h>