Does crtdbg.h conflict with DirectX? - c++

I just discovered the hidden gem crtdbg.h which makes memory leak detection so much easier. Unfortunately, when I linked DirectX into my program today, I got some errors I've never seen before.
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.h(425): error C2059: syntax error : 'constant'
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.h(425): error C2091: function returns function
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.h(425): error C2802: static member 'operator new' has no formal parameters
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.h(426): error C2059: syntax error : 'constant'
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.h(426): error C2090: function returns array
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.inl(1003): error C2761: 'void *(__cdecl *_D3DXMATRIXA16::operator new(void))(size_t)' : member function redeclaration not allowed
1>e:\program files (x86)\microsoft directx sdk (june 2010)\include\d3dx10math.inl(1003): fatal error C1903: unable to recover from previous error(s); stopping compilation
It seems like when crtdbg overrides the new operator, it breaks something in the DirectX SDK (in case you didn't notice in the errors, I am using the DirectX 11 SDK). Is anything like this documented? A few searches didn't yield any results. I really hope I can continue to use these memory debugging tools, and any workarounds would be greatly appreciated!

Ok, I figured it out. I found this post via Google. (I wish Stack Overflow had shown it to me on the sidebar when I was typing this! Or maybe it did and I missed it...).
Basically, I need to move the including of crtdbg.h, stdlib.h and the definition of _CRTDBG_MAP_ALLOC to a separate header, and use the Forced Include File option under C/C++ >> Advanced in the project properties page to force that include file everywhere. This seems to make it override all other new overrides.

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'

Error in including atlconv.h in VS 15.7

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?

Visual Studio 2017 Compile DirectX8

I'm working on an old project that is using DirectX 8, I wonder if there is a way to make Visual Studio 2017 compile the code while still using DirectX8.
Windows SDK = 10.0.16299.0
Toolset = msvc141
I'm using the modern look of MFC applications as sample project, but it's probably has nothing to do with it as it happens only when I include D3DX8.h for example, I get a lot of syntax errors on DirectX side.
I wonder if there is a way to work on directx 8 without me having to keep using Visual C++ 6.0.
1>c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(155): error C2011: '_D3DLIGHTTYPE': 'enum' type redefinition
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(180): note: see declaration of '_D3DLIGHTTYPE'
1>c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(189): error C2011: '_D3DSHADEMODE': 'enum' type redefinition
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(214): note: see declaration of '_D3DSHADEMODE'
1>c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(196): error C2011: '_D3DFILLMODE': 'enum' type redefinition
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(221): note: see declaration of '_D3DFILLMODE'
1>c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(208): error C2011: '_D3DBLEND': 'enum' type redefinition
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(228): note: see declaration of '_D3DBLEND'
1>c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(225): error C2011: '_D3DBLENDOP': 'enum' type redefinition
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(255): note: see declaration of '_D3DBLENDOP'
1>c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(234): error C2011: '_D3DTEXTUREADDRESS': 'enum' type redefinition
1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(264): note: see declaration of '_D3DTEXTUREADDRESS'
The Windows SDK does not support DirectX 8 development. Since the first time DirectX became 'part of the OS' was DirectX 9.0c with Windows XP Service Pack 2, the Windows SDK has only ever had Direct3D 9 or later headers.
The last legacy DirectX SDK to support DirectX 8 was August 2007 (the end of life release of the DirectX SDK was June 2010). That was using VS 2005 / VS 2008 with the Windows SDK 6.0.
There are definitely challenges mixing the legacy DirectX SDK with the Windows SDK. There are instructions on Microsoft Docs for using the June 2010 version, but as I noted that doesn't include Direct3D 8.
See DirectX SDKs of a certain age and A Brief History of Windows SDKs
You need to add the library and include directory of <winsdk6.0a> and to your project
PlatformToolsets select v100
props file:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="Current"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- http://msdn.microsoft.com/en-us/library/ms171458.aspx -->
<PropertyGroup Label="UserMacros">
<WinSDKDir>C:\Program Files\Microsoft SDKs\Windows\v6.0A</WinSDKDir>
<WinSDKInc>$(WinSDKDir)\include</WinSDKInc>
<WinSDKLib>$(WinSDKDir)\lib</WinSDKLib>
<DX8SDKDir>$(UserSDKDir)\DirectX\DX8.1bSDK</DX8SDKDir>
<DX8SDKInc>$(DX8SDKDir)\include</DX8SDKInc>
<DX8SDKLib>$(DX8SDKDir)\lib</DX8SDKLib>
</PropertyGroup>
<PropertyGroup>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(WinSDKInc);$(DX8SDKInc);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(WinSDKLib);$(DX8SDKLib);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>d3d8.lib;DxErr8.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Debug'">d3dx8d.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies Condition="'$(Configuration)'=='Release'">d3dx8.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
</Project>
From the error line :
c:\mmorpg\directx\dx3d8\dxf\dxsdk\include\d3d8types.h(155): error C2011: '_D3DLIGHTTYPE': 'enum' type redefinition 1>c:\program files (x86)\windows kits\10\include\10.0.16299.0\shared\d3d9types.h(180): note: see declaration of '_D3DLIGHTTYPE'
=> you are including obviously two version of directX headers d3d8types.h and d3d9types.h , referencing the exact same symbols.
I think it should be only one of them included.
To trace what cause the include of d3d9types.h file, in Visual Studio, you can activate the showIncludes compiler option :
Show includes compiler option

Linker error, any ideas/explanation?

Been following along with a tutorial for direct x. My most recent compile cam up with an entire slew of what I think are linker errors. I don't know if it is specific to me or not. I have the code here if anybody want to take a kick at the can. Otherwise, any tips on fixing the errors? They're mostly '__in' has not been declared and expected ',' or '...' before '&' token within some header file DXGI.h
Errors:
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\dxgi.h|286|error: '__in' has not been declared|
and
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\dxgi.h|286|error: expected ',' or '...' before '&' token|
Are the first two and Im getting this warning:
C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\DXGI.h|9|warning: ignoring #pragma warning [-Wunknown-pragmas]|
I've tried swapping out the DXGI.h file and it still doesn't work along with trying the tutorials exact code(copy and paste) to eliminate chance for error.
Update: Just tried it on an alternate computer and errored out as well.

error C2065: 'errno' : undeclared identifier in <string> in Visual Studio 2012

I had a project running in Visual Studio 2010. Now I am using Visual Studio 2012.
Now I am getting below error while building the project.
I have looked into Google and SO as well. But no where I got any solution.
c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(557): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(562): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(574): error C2065: 'errno' : undeclared identifier
2>c:\program files\microsoft visual studio 11.0\vc\include\string(579): error C2065: 'errno' : undeclared identifier
I have tried with including stdlib.h into the sting header file but still I am getting this same error.
Any help appreciated.
There could be several possible reasons for this problem. The
first thing you should do is to create a one line source:
#include <string>
and nothing else, and try to compile it. If this doesn't
compile, there is a problem with your installation, and you
should reinstall it. Then, just to be sure, delete everything
in your source tree except the actual sources, project files and
solution, and rebuild. There may be some old files laying
around which are somehow causing the problem. I doubt it, but
this is something you should do anyway, any time you upgrade
a compiler, or even just install a patch. (If you've got
everything under source code control, which you should, the
simplest solution is just to delete everything, and do a new,
clean checkout.)
If these measures don't solve the problem (and somehow,
I suspect they won't), there's a problem in your code base
somewhere. errno is required to be a macro by the standard;
to get the error message you cite, the macro must be undefined.
<string> includes (indirectly) a file which defines it. Given
this, the only cause I can think of is that an earlier include
file has already included a file which defines errno, and then
#undefed it. To verify this, put your #include <string> as
the very first include of your source, and see if this solves
the problem. If it does, then you have to find the file which
does the #undef, and fix it.
I had the same issue. Strangely enough, the problem was not including "using namespace std;" under the header file includes. Apparently, program would recognize "string" unless I did this, even though "char", "float", etc were recognized.