Error with RegOpenKeyEx() - c++

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>

Related

I included <winuser.h>, but compiler throws "was not declared" at MonitorFromWindow

There is already a post about it, but it didn't solve the error. I tried commenting out the if on winuser.h, but it did no effect.
// Header
#include <windows.h>
#include <winuser.h>
// Cpp
monitorA = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY); // Errors
GetMonitorInfo(monitorA, &monitorAInfo); // No error
error: 'MonitorFromWindow' was not declared in this scope
error: 'MONITOR_DEFAULTTOPRIMARY' was not declared in this scope
Also, I am using Code::blocks with gcc compiler.
Assuming your copy of <winuser.h> actually supports MonitorFromWindow(), then make sure that you have WINVER set to 0x0500 or higher to enable MonitorFromWindow(). See the following for more details:
Using the Windows Headers: Setting WINVER or _WIN32_WINNT
Update WINVER and _WIN32_WINNT
What's the difference between WINVER, _WIN32_WINNT, _WIN32_WINDOWS, and _WIN32_IE?

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 while building OpenCV :: MonitorFromRect was not declared in this scope

I was trying to build OpenCV version 2.4.8 to use it with CodeBlocks and MinGw. I followed the instructions from here. But I got the following error. I have no clue how to solve it. I didn't find anything useful by searching in the net.
This is also not solving.
I don't want to mess with the openCV code, I intend to use OpenCV in my project and this is first time I am using it.
[ 26%] Built target pch_Generate_opencv_highgui
[ 26%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp: In function 'void cvSetModeWindow_W32(const char*, double)':
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp:477: error: 'MonitorFromRect' was not declared in this scope
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp: In function 'LRESULT MainWindowProc(HWND__*, UINT, WPARAM, LPARAM)':
C:\Program Files (x86)\opencv\sources\modules\highgui\src\window_w32.cpp:1355: error: 'MonitorFromRect' was not declared in this scope
mingw32-make.exe[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj] Error 1
mingw32-make.exe[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
I tried to manually include the prototype of the function in the file, but then it comes to linking error.
will anyone please tell me what may have gone wrong here? How can I solve it?
It seems All the changes from recent commit is not reflected in your check out. To resolve the problems, make the following changes:
In modules/highgui/src/precomp.hpp, add the + marked line:
#if defined WIN32 || defined WINCE
+ #if !defined _WIN32_WINNT
+ #ifdef HAVE_MSMF
+ #define _WIN32_WINNT 0x0600 // Windows Vista
+ #else
+ #define _WIN32_WINNT 0x0500 // Windows 2000
+ #endif
+ #endif
+
#include <windows.h>
And in modules/highgui/src/window_w32.cpp, remove the - marked lines:
#if defined WIN32 || defined _WIN32
-#define COMPILE_MULTIMON_STUBS // Required for multi-monitor support
-#ifndef _MULTIMON_USE_SECURE_CRT
-# define _MULTIMON_USE_SECURE_CRT 0 // some MinGW platforms have no strncpy_s
-#endif
-
-#if defined SM_CMONITORS && !defined MONITOR_DEFAULTTONEAREST
-# define MONITOR_DEFAULTTONULL 0x00000000
-# define MONITOR_DEFAULTTOPRIMARY 0x00000001
-# define MONITOR_DEFAULTTONEAREST 0x00000002
-# define MONITORINFOF_PRIMARY 0x00000001
-#endif
-#ifndef __inout
-# define __inout
-#endif
-
#ifdef __GNUC__
# pragma GCC diagnostic ignored "-Wmissing-declarations"
#endif
#include <commctrl.h>
-#include <winuser.h>
#include <stdlib.h>
#include <string.h>
This will solve the build error.
I had the same problem when building OpenCV 3.0.0 RC1 with mingw32 and the TBB library enabled.
The fix from Rajdhar is already included in the precomp.h file. However, due when building OpenCV with the TBB library, the extra includes trigger the same problem again.
I provisionally solved the issue by moving the definition of _WIN32_WINNT indicated by Rajdhar to an earlier point in the file, before the opencv/core includes:
#ifndef __HIGHGUI_H_
#define __HIGHGUI_H_
#include "opencv2/highgui.hpp"
// MOVED UP
#if defined WIN32 || defined WINCE
#if !defined _WIN32_WINNT
#ifdef HAVE_MSMF
#define _WIN32_WINNT 0x0600 // Windows Vista
#else
#define _WIN32_WINNT 0x0500 // Windows 2000
#endif
#endif
#include <windows.h>
#undef small
#undef min
#undef max
#undef abs
#endif
// END MOVED
#include "opencv2/core/utility.hpp"
#include "opencv2/core/private.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgcodecs/imgcodecs_c.h"
#include "opencv2/highgui/highgui_c.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <assert.h>
// MOVED FROM HERE
#ifdef HAVE_TEGRA_OPTIMIZATION
#include "opencv2/highgui/highgui_tegra.hpp"
#endif
I've had exactly the same problem, and after a quick glance at the file winuser.h, I knew what's going on and added necessary macros to CFLAGS and CXXFLAGS in the command line:
CFLAGS=-D_WIN32_WINNT=0x0500 CXXFLAGS=-D_WIN32_WINNT=0x0500 make
However, the problem was still unsolved. Adding VERBOSE=1 showed that the custom CFLAGS and CXXFLAGS did not take effect at all. It was wierd and I think it should have something to do with my environment, though, i still could not figure it out. Anyway, #Rajdhar 's answer solved my problem, thanks.

NTDDI_VERSION setting conflicts with _WIN32_WINNT setting

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.

error C1189 after installing Visual Studio 2010

I installed VS2010 after a drive crash, prior I had VS2005 and everything was fine.
Now on compiling a C++ app that was fine previously I am seeing a couple of errors which I just cannot figure out.
Error 1 error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended. C:\Program Files\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlcore.h 35 1 BIOXGINA
#ifndef __ATLCORE_H__
#define __ATLCORE_H__
#pragma once
#ifdef _ATL_ALL_WARNINGS
#pragma warning( push )
#endif
#pragma warning(disable: 4786) // identifier was truncated in the debug information
#pragma warning(disable: 4127) // constant expression
#include <atldef.h>
#include <windows.h>
#include <ole2.h>
#include <limits.h>
#include <tchar.h>
#include <mbstring.h>
#include <atlchecked.h>
#include <atlsimpcoll.h>
34. #if _WIN32_WINNT < 0x0403
35. #error This file requires _WIN32_WINNT to be #defined at least to 0x0403. Value 0x0501 or higher is recommended.
36. #endif
#pragma pack(push,_ATL_PACKING)
namespace ATL
{
/////////////////////////////////////////////////////////////////////////////
// Verify that a null-terminated string points to valid memory
inline BOOL AtlIsValidString(
_In_z_count_(nMaxLength) LPCWSTR psz,
_In_ size_t nMaxLength = INT_MAX)
{
(nMaxLength);
return (psz != NULL);
}
If I comment out the above lines, I then get
error C3861 Identifier not found on line 111 below.
I presume I'm only getting this because I commented the above lines ?
HRESULT Init() throw()
{
HRESULT hRes = S_OK;
111. if (!InitializeCriticalSectionAndSpinCount(&m_sec, 0))
{
hRes = HRESULT_FROM_WIN32(GetLastError());
}
return hRes;
}
I would appreciate any assistance on this. Don't really want to reinstall 2005.
This Microsoft Connect issue has this potential solution:
edit file "stdafx.h" and change the value defined for _WIN32_WINNT and WINVER to 0x0502.
More discussion here about this error on the MSDN C++ forum: Problem with older VC Solution.
Your project targets a Windows version that is no longer supported by the newer compiler (or anything else).
You have to select a minimum target version that is Windows XP ("Windows 5") or later.
Thank you both for the replies.
I managed to get rid of the error message as follows. The Context.h looked liked this.
#pragma once
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include <winwlx.h>
#include <ObjBase.h>
#include <comdef.h>
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <vector>
I moved the #define _WIN32_WINNT 0x0400 to then end after all the includes, and it compiled Ok. Odd, but it worked.
I will however alter it to 0x0502 as suggested.
thanks
Project Property –> Configuration Properties –> C/C++ -> Command Line ->Additional Options
:add this code
/D “_WIN32_WINNT=0×0501”
if in Windows server 2003,0×0501chagnes to 0×0502;
if in Windows 7, 0×0501chagnes to 0×0601
works well