Error in including atlconv.h in VS 15.7 - c++

We have a legacy code that uses ATL that was running fine on Windows until we used VS2017 15.6. When we upgraded to 15.7, we started hitting the following compilation error:
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\atlmfc\include\atlconv.h(395): error C3861: 'AtlThrowLastWin32': identifier not found
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\atlmfc\include\atlconv.h(406): note: see reference to class template instantiation 'ATL::CA2WEX' being compiled
A quick search found the following link: https://naughter.wordpress.com/2017/01/02/a-comprehensive-comparison-of-the-mfc-atl-changes-in-vs-2017-rc-compared-to-visual-studio-2015-update-3-part-1/
which has the following information:
Line 91: Minor change to comment to fix spelling mistake
Line 94: AtlThrowImpl is now declared as __declspec(noreturn)
Line 112: AtlThrowLastWin32 is now declared as __declspec(noreturn)
We are using both
define _ATL_NO_EXCEPTIONS
define _ATL_CUSTOM_THROW
Has anyone successfully compiled a C++ project that includes ATL on latest VS (15.7) with _ATL_NO_EXCEPTIONS and _ATL_CUSTOM_THROW turned on?

Related

std::filesystem doesn't work in DLL project

I feel sorta silly asking this question, but I just cannot find a solution anywhere on the internet.
Notes:
I am using VS2019
C++17 is enabled
My problem is the following:
I want to iterate files in a directory with std::filesystem. To do so, I need to use the directory_iterator. However, when I include the filesystem library, it doesn't find the directory_iterator, so I checked the filesystem header file. It threw me a bunch of errors. I also cannot use experimental/filesystem because for some reason the path class also has errors which make the string functions unusable.
However, when I create a fresh console application, it works fine for me. No errors, directory_iterator has been found, I can iterate without issues.
Here is a small snippet of what the errors I'm being given when trying to compile:
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(917,28): warning C4003: not enough arguments for function-like macro invocation 'concat'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2365: '_InIt': redefinition; previous definition was 'template parameter'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921): message : see declaration of '_InIt'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\experimental\filesystem(921,1): error C2061: syntax error: identifier '_First_InIt'

GDI+ library causes "error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'" in VS2017 when compiled for XP

I'm trying to include the following definitions for GDI+ into my Win32 C++ project that is compiled under Visual Studio 2017:
#include <objidl.h>
#include <gdiplus.h>
#pragma comment (lib,"Gdiplus.lib")
I need to compile this project to support Windows XP. So in the project properies I selected: Platform Toolset as Visual Studio 2017 - Windows XP (v141_xp):
But when I compile it the GDI+ library gives me this:
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier'
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusheaders.h(891): error C4596: 'EmfToWmfBits': illegal qualified name in member declaration
1>c:\program files (x86)\microsoft sdks\windows\v7.1a\include\gdiplusstringformat.h(220): error C4596: 'GetTrimming': illegal qualified name in member declaration
Any idea how to fix this?
Add this line before the very first(!) #include of COM-related header to fix objbase.h(239): error C2760: syntax error: unexpected token 'identifier', expected 'type specifier' :
typedef struct IUnknown IUnknown;
This fix works, because the line in objbase.h(239) mentioned in the error contains static_cast<IUnknown*>(*pp); despite that IUnknown still haven't been declared in that place.
I kinda got it to compile, but this is definitely not a good solution. I'm posting it here as a temp workaround until Microsoft gets their heads out of their ___es. Also if anyone finds a better way, please let me know.
I basically had to downgrade the entire project to Visual Studio 2015 - Windows XP (v140_xp) just to compile one badly written library:
This created a problem of its own with the std libraries:
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstdio(50): error C4995: 'sprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstdio(53): error C4995: 'vsprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstring(20): error C4995: 'strcat': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cstring(21): error C4995: 'strcpy': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(29): error C4995: 'swprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(30): error C4995: 'vswprintf': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(32): error C4995: 'wcscat': name was marked as #pragma deprecated
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\cwchar(34): error C4995: 'wcscpy': name was marked as #pragma deprecated
So I had to shunt those errors of unsafe functions:
#pragma warning( push )
#pragma warning( disable: 4995 )
#include <stdio.h>
#include <new>
#include <string>
#pragma warning( pop )
Which is far from ideal!
(You're basically sacrificing security of the app just to compile that damn GDI+ library.)
There's a way to get this to work if you're prepared to edit the Windows header files.
In objbase.h, comment out line 239 or change it to:
static_assert (std::is_base_of <IUnknown *, *pp>::value, "pp must derive from IUnknown");
In gdiplusheaders.h, line 891, remove the redundant qualifier (Metafile::).
In gdiplusstringformat.h, line 220, remove the redundant qualifier (StringFormat::).
Hopefully, that will fix things for you without breaking anything.
Although the question is old, just adding what worked for me.
In my case including windows.h and compiling with VS2017 v141_xp toolset was causing me error: syntax error: unexpected token 'identifier', expected 'type specifier'.
This resolved my issue link

Visual studio 2015 xlocnum C++ issue

I am using Visual studio version 14.0.25431.01 Update 3. While upgrading an existing project in C++ from VS2k13 to VS2k15, I am getting the following build errors in xlocnum file placed at C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocnum.
Error C2912 explicit specialization 'void std::numpunct<char>::_Getvals(void)' is not a specialization of a function template Scripttest C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocnum 192
and
Error C2061 syntax error: identifier '_Elem2' InterPTest C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xlocnum 188.
Following code in xlocnum is throwing the error
template<_Elem2>
void _Getvals(_Elem2, const lconv *_Ptr, _Locinfo::_Cvtvec _Cvt)
{ // get values
_Dp = _MAKLOCCHR(_Elem2, _Ptr->decimal_point[0], _Cvt);
_Kseparator = _MAKLOCCHR(_Elem2, _Ptr->thousands_sep[0], _Cvt);
}
After explicitly typenameing template<_Elem2> with template, error resolves but the change has to be made in the windows file xlocnum itself, so its doesn't seem a valid solution. Please suggest a resolution for this issue, Thanks

Compiling Audacity with VisualStudio 2015 and C++ produces multiple C1189 & C4005 errors

I am using Visualstudio 2015. On Windows 10.I am trying to specifically use the latest VS and SDKs, I do not want to back track to VS2013.
I have gone through the entire code base of Audacity, and changed the instances of
#define snprintf _snprintf
to
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
However, on rebuilding - I'm still getting these errors.
22>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1925): warning C4005: 'snprintf': macro redefinition
22> C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1925): note: command-line arguments: see previous definition of 'snprintf'
22>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1927): fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration
I can not see how to get around this? Where is it colliding and thus producing the fatal error.
There are 24 Solutions in the build, and all but three of them build. Theo nes that don't build so far are:
libnyquist
libsndfile
lv2

C++ Visual Studio 2012 issues

Updated problem #3
I've narrowed the problem. It seems that simply including <thread> makes the compiler go mad.
I am not even making any thread calls, just including it.
I have tried enabling /EHsc and also disabling it.
Disabled, I get:
I get these 6 messages:
Error 1 error C2220: warning treated as error - no 'object' file generated (main.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 313 1 cefclient
Warning 2 warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc (main.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 313 1 cefclient
Error 3 error C2220: warning treated as error - no 'object' file generated (Program.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 313 1 cefclient
Warning 4 warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc (Program.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 313 1 cefclient
Error 5 error C3861: '__uncaught_exception': identifier not found (main.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 4774 1 cefclient
Error 6 error C3861: '__uncaught_exception': identifier not found (Program.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 4774 1 cefclient
And if enabled (Configuration Properties -> C/C++ -> Code Generation & in the Command Line)
Error 1 error C3861: '__uncaught_exception': identifier not found (main.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 4774 1 cefclient
Error 2 error C3861: '__uncaught_exception': identifier not found (Program.cpp) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\concrt.h 4774 1 cefclient
I did a simple test with a new, blank project, including thread and just compiling. It went fine, no errors.
However in my main project I am using Chromium Embedded Framework v3, which seems to interact strangely with the thread inclusion?
Seems odd that simply including it would make such a mess.
Any ideas?
Update:
By removing the _HAS_EXCEPTIONS=0 flag entirely and rebuilding the project from CMake, I enter a state where the project won't even compile.
Due to this change it throws out a ton of warnings and errors from various files.
Errors such as:
Warning 230 warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc (C:\Users\mads\Desktop\cef_binary_3.2526.1347.gcf20046_windows32\cefclient\browser\client_handler_osr.cc) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale 337 1 cefclient
According to a lot of asking around and googling, the solution to this is to specify /EHsc in Project Properties -> C/C++ -> Code Generation -> Enable C++ Exceptions = Yes(/EHsc).
As well as setting the flag /EHsc in the Command Line input field.
However, nothing changes. The same errors come out as if nothing was changed.
Update:
The error
Warning 2 warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc (C:\Users\mads\Desktop\cef_binary_3.2556.1368.g535c4fb_windows32\libcef_dll\transfer_util.cc) C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale 337 1 libcef_dll_wrapper
comes from the project "libcef_dll_wrapper", despite the fact that I HAVE speficied /EHsc in its project settings! Both in C++ -> Code Generation page and the Command Line
Solution edit:
Turns out that cmake files would override my set settings everytime I attempted to build or run the project, hence rendering any changes I made un-used, despite being set!
I was able to solve the problem by editing the project's cmake files directly.
Never used cmake before, so in the end it became a learning experience.
I have tested my project with thread inclusion now and it compiles as expected!
Thanks to all for great suggestions
Make sure neither the code nor the compiler command line define _HAS_EXCEPTIONS=0.
Compiling VC++ 12.0 with _HAS_EXCEPTIONS=0 and including concrt.h causes a compiler error:
If a source file is compiled with VC++ 12.0 with _HAS_EXCEPTIONS set to 0 and the source includes, whether directly or indirectly, concrt.h, the compiler gives an error of:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\concrt.h(4774) : error C3861: '__uncaught_exception': identifier not found
[...] Macro _HAS_EXCEPTIONS=0 is undocumented and unsupported by Microsoft.
It may work with some parts of the STL library for legacy reasons, but it won't be compatible with ConcRT library (concrt.h) since ConcRT depends on exceptions for cancellation.