Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using the latest Visual Studio 2022 / C++ / MFC, Windows SDK 10.0, Platform toolset 10.0 (latest installed version), C++ Language Standard ISO C++ 17 Standard and building 64 bit.

I started with the standard MDI template, added some stuff (Scintilla edit control, which requires >= ISO C++ 17) and successfully compiled.

Now I'm integrating existing source code from previous development (which compiles under ISO C++ 14, but that may not be the explanation for what I'm about to describe).

My compile is now failing with the following errors:

Error	C1189	#error:  CTaskDialog is not supported on Windows versions prior to Vista.	Visual SQL Studio	C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\atlmfc\include\afxtaskdialog.h	18		


... and

Error	C2664	'INT getaddrinfo(PCSTR,PCSTR,const ADDRINFOA *,PADDRINFOA *)': cannot convert argument 1 from 'LPCTSTR' to 'PCSTR'	Visual SQL Studio	C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\atlmfc\include\atlsocket.h	163		


So, not in my code. In both cases, there is conditional compilation based on Windows version #defines. For example, for the first error, the code is:

#if (NTDDI_VERSION < NTDDI_VISTA) // min Windows Vista required
#error CTaskDialog is not supported on Windows versions prior to Vista.
#endif


My interpretation of this is that the compiler sees value of NTDDI_VERSION as less than the value of NTDDI_VISTA and therefore fires the error.

BUT, I am only using all of the defaults created by the project template for pch.h, framework.h and targetver.h, which (if my understanding is correct) equates to
#include <SDKDDKVer.h>
.

So, I'm scratching my head on the explanation or cure for this issue. I am definitely not redefining Windows version #defines elsewhere. However, I think
NTDDI_VERSION
is actually undefined at the point in the header file where the version test is applied, because this edit (sacrilege, I know) causes the compile to succeed:

#undef NTDDI_VERSION
#define NTDDI_VERSION NTDDI_WIN10

#if (NTDDI_VERSION < NTDDI_VISTA) // min Windows Vista required
#error CTaskDialog is not supported on Windows versions prior to Vista.
#endif


Clearly editing AfxTaskDialog.h is not an acceptable solution, so I'd be incredibly grateful for any suggestion on how to diagnose / resolve this issue.

Summary of framework/platfirm defines
pch.h - #include "framework.h" as first line.
framework.h - #include "targetver.h" as first line
targetver.h - #include <sdkddkver.h> as first line

What I have tried:

I have explicitly #defined NTDDI_VERSION in pch.h and / or framework.h and / or targetver.h. I have forced the NTDDI_VERSION to pass the #if (NTDDI_VERSION < NTDDI_VISTA) test by hard coding NTDDI_VERSION (which works but is not a viable solution).
Posted

1 solution

To figure out the first issue under compiler settings on C/C++ Advanced tab choose "show includes" and it display during build the includes sequence - this way you can find is the NTDDI_VERSION defined at all before the file you interested in, or it maybe undefined somewhere. Also be sure that SDKDDKVer.h included first - try to put it first in your precompiled header file (pch.h)
The second error comes that TCHAR defined as the UNICODE character but the function expect the CHAR. Change settings to the MBCS instead of UNICODE (General tab in properties and select "Character Set" value) - this may help if its not your code, otherwise you can figure out the passed parameter in code.

Hope this help.

Regards,
Maxim.
 
Share this answer
 
Comments
peterboulton 24-Jan-24 6:32am    
Hi Maxim. Many thanks for taking the trouble to answer my question - much appreciated. On the first issue, choosing "show includes", the first few lines of the compiler output are:

1>stdafx.cpp
1>Note: including file: G:\Visual Studio 2010 Projects\Visual SQL Studio (C++)\Visual SQL Studio\stdafx.h
1>Note: including file: G:\Visual Studio 2010 Projects\Visual SQL Studio (C++)\Visual SQL Studio\framework.h
1>Note: including file: G:\Visual Studio 2010 Projects\Visual SQL Studio (C++)\Visual SQL Studio\targetver.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\shared\SDKDDKVer.h
1>Note: including file: C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.38.33130\atlmfc\include\afxwin.h

So, they are compiled before the file which fires the compile error. I also tried moving SDKDDKVer.h to the first line of pch.h, but the error still fires.

On the second error, I would like to stay UNICODE and am not even aware of any of my code calling getaddrinfo(). I didn't paste in the code that triggers the error, which is from atlsocket.h. But it's the same sort of error on the version #defines as my first error. The code in AtlSocket.h is:

#if _WIN32_WINNT < 0x0502
#ifdef _UNICODE
USES_CONVERSION_EX;
const char * pszHost = W2CA_EX(szHost, _ATL_SAFE_ALLOCA_DEF_THRESHOLD);
const char * pszPortOrServiceName = W2CA_EX(szPortOrServiceName, _ATL_SAFE_ALLOCA_DEF_THRESHOLD);
if(pszHost == NULL || pszPortOrServiceName == NULL )
{
WSASetLastError(WSA_NOT_ENOUGH_MEMORY);
return SOCKET_ERROR;
}
#else
const char * pszHost = szHost;
const char * pszPortOrServiceName = szPortOrServiceName;
#endif
return ::GetAddrInfo(pszHost, pszPortOrServiceName, &hints, &m_pAddrs);
#else
return ::GetAddrInfo(szHost, szPortOrServiceName, &hints, &m_pAddrs);
#endif

If the #define was successfully defined as >= 0x502 then the other version of the function would be compiled and (I think) I would not get this compile error.

Thank you, again, for your help.
Maxim Kartavenkov 24-Jan-24 6:47am    
Maybe WIN32_WINNT / NTDDI_VERSION like the UNICODE defined in the project settings directly for your configuration? Try to check in there: preprocessor definitions and additional options of the command line
peterboulton 24-Jan-24 6:58am    
Hi Maxim, the C/C++ project settings command line is:

/JMC /Yu"stdafx.h" /ifcOutput "x64\Debug\" /GS /W3 /wd"4996" /Zc:wchar_t /I"G:\Visual Studio 2022 Projects\Visual SQL Studio (C++)\ScriptDomUtils" /ZI /Gm- /Od /sdl /Fd"x64\Debug\vc143.pdb" /Zc:inline /fp:precise /D "_WINDOWS" /D "_DEBUG" /D "_USE_PCH" /D "_CRT_SECURE_NO_WARNINGS" /D "_VS2008_" /D "_UNICODE" /D "UNICODE" /D "_AFXDLL" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /showIncludes /MDd /std:c++17 /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\Visual SQL Studio.pch" /diagnostics:column

I can't see an issue there... can you?

Thanks again for your kindness.
Maxim Kartavenkov 24-Jan-24 7:02am    
also - try to remove "_VS2008_" definition - project not from VS2022 - looks like it's even from VS2008
peterboulton 24-Jan-24 7:16am    
Yes, but the _VS2008_ is my 'invention' and only used for conditional compilation of my known code. I don't believe it has any other function in the code.

My other projects also define it and compile correctly (though for C++ ISO 14, not 17).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900