error C1189 after installing Visual Studio 2010 - c++

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

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?

GetAncestor: Undeclared identifier

I'm using Visual Studio 6 for backward compatibility reasons and I need
to use GetAncestor() like this to create a dll :
HWND ancestorhandle = GetAncestor(myvar, 2);
I've included these header files:
#include <windows.h>
#include "stdafx.h"
#include "offlinelib.h"
#include <stdio.h>
As per the documentation:
GetAncestor function
But while compiling, I get an error:
GetAncestor: Undeclared identifier
What am I doing wrong?
Try moving the #include "stdafx.h" (precompiled header) up, making it the first include line.
Solved by adding
#ifdef WINVER
#undef WINVER
#endif
#define WINVER 0x500
on top of stdafx.h

'GetProcessIdOfThread': identifier not found

Here is my codes in stdafx.h :
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#define _WIN32_WINNT 0x0502
#include "winsock2.h"
#include "windows.h"
#include "stdio.h"
#include "Iphlpapi.h"
#include <psapi.h>
#include "Ntsecapi.h"
#include "txdtc.h"
#include "xolehlp.h"
#include <iostream>
#include <tchar.h>
// TODO: reference additional headers your program requires here
As you see i have included "windows.h"
And here is main codes :
#include "stdafx.h"
...
if (hThread && dwRpcssPid == GetProcessIdOfThread(hThread))
...
My errors are :
'GetProcessIdOfThread': identifier not found
IntelliSense: identifier "GetProcessIdOfThread" is undefined
How can i fix these errors?
The function is not available with _WIN32_WINNT values less than 0x0600 AKA _WIN32_WINNT_VISTA. If you change your code this way, you will get it working:
//#define _WIN32_WINNT 0x0502
#define _WIN32_WINNT 0x0600
The function is available since Vista, to target Vista+ you should have this value defined respectively.
To target latest versions of API with current SDK, you can simply include SDKDDKVer.h and those values will be defined for you/
//#define _WIN32_WINNT 0x0502
#include <SDKDDKVer.h>
See also:
What is _WIN32_WINNT and how does it work?
GetProcessIdOfThread's platform requirements states:
Windows Vista [desktop apps only]
Windows Server 2003 [desktop apps only]
And the header requirements states:
Processthreadsapi.h on Windows 8 and Windows Server 2012
So:
Make sure your windows SDK is up-to-date
Make sure you have specified your platform requirements properly.
Make sure you're including the right header file.
If you are using windows 8 you need to include : Processthreadsapi.h
See the MSDN references in the header section.

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.

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>