Visual Studio 2017 Compile DirectX8 - c++

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

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'

Update visual studio 2017, now getting compile error C7510: 'Callback': use of dependent template name must be prefixed with 'template'

I tried compiling my project as usual after the update (15.8.0). I set showincludes to yes to figure out where the error originates, but it's all system code. Starting with stdafx.cpp, it goes through all the includes and errors out:
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\poppack.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\poppack.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\eventtoken.h
1>Note: including file: C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\shared\pshpack8.h
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\winrt\wrl\event.h(316): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
1>c:\program files (x86)\windows kits\10\include\10.0.17134.0\winrt\wrl\event.h(324): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
Has anyone seen this before? I googled up and down to find an answer to no avail. Short of modifying the windows sdk, not sure what to do.
Edit:
In my installed windows SDK, the error was in the file-
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\winrt\wrl\event.h
Changed line 316: return DelegateHelper::Traits::Callback(Details::Forward(callback));
to: return DelegateHelper::Traits::template Callback(Details::Forward(callback));
and line 324: return DelegateHelper::Traits::Callback(
to return DelegateHelper::Traits::template Callback(Details::Forward(callback));
Since modifying an sdk is not really a solution, Peng Du's solution by selecting non conformance in the configuration window is the way to go.
I have legacy projects and I compared the project settings side by side, finally I successfully built the new project by setting: Configuration Properties > C/C++ > Language > Conformance mode = No
When you use a dependent template name, you have to use a template keyword, for example:
foo.template bar<T>();
Till some moment MSVC was not strict about using typename and template disambiguators, but after an update the rules have changed.
The problem is in the Windows Runtime Library and some change to Visual Studio broke it. I have the same issue on this laptop which is updated to 15.8.2, my machine at home running an earlier version does not do this, since the exact same code compiles on my other machine, it's got to be a bug in VS, or a change required in WRL/event class.
EDIT: Fix to the return values above worked, bug is in the SDK, you should NOT disable /permissive- as this enables protection against Spectre and other security enhancements.

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?

Libs ,DLLs and .h files

Im a C# guy thats why I'm lost here, this project claims to have compiled that library for Windows https://soildgeo.codeplex.com/releases/view/108738
the folder comes with Include,Lib64 and Bin64 folders. If I'm not mistaken, I only need to copy .lib files to the VC/lib folder and the folders in include to VC/include folder, so that I can start coding against these APIs, they appear in the #include<> intellisense but then they don't compile. my questions are, are my assumptions on this whole process is right ? if not what are the right steps ? and lastly, do I need to use the Dlls found in Bin64 folder at any point ?
Im using VS2013
Thanks in advance
Edit
1>------ Build started: Project: PhysBAMTest, Configuration: Debug x64 ------
1> main.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2146: syntax error : missing ';' before identifier 'attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cout' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163): error C2143: syntax error : missing ';' before '='
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2146: syntax error : missing ';' before identifier '__attribute__'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2530: 'PhysBAM::LOG::anonymous-namespace'::cerr' : references must be initialized
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2065: 'unused' : undeclared identifier
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2374: 'PhysBAM::LOG::anonymous-namespace'::__attribute__' : redefinition; multiple initialization
1> C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(163) : see declaration of 'PhysBAM::LOG::anonymous-namespace'::attribute'
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\PhysBAM_Tools\Log\LOG.h(164): error C2143: syntax error : missing ';' before '='
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Edit
after adding the WIN32 macro based on an answer below , I got a linker error this time
Error 1 error LNK2019: unresolved external symbol "class std::basic_ostream > & __cdecl PhysBAM::LOG::cout_Helper(void)" (?cout_Helper#LOG#PhysBAM##YAAEAV?$basic_ostream#DU?$char_traits#D#std###std##XZ) referenced in function "void __cdecl PhysBAM::LOG::anonymous namespace'::dynamic initializer for 'cout''(void)" (??__Ecout#?A0x5bbeb782#LOG#PhysBAM##YAXXZ) C:\Users...\Documents\Visual Studio 2013\Projects\PhysBAMTest\PhysBAMTest\main.obj PhysBAMTest
All those attribute, unused, __attribute__ are what some call GNU-ishms, that is, features specific to the GCC compatible compilers (GCC itself, Clang, ICC and others). But MS VC does not aim for GCC compatibility, so they just don't work.
The people that did the port to Windows managed to remove these construct by using a few precompiler tricks, I think in the file Utilities/PHYSBAM_OVERRIDE.h. But for those to work you have to define the macro WIN32. Do that in the project "C/C++ Preprocessor Settings" page, not in the code, so it will be defined for all the source files at once.
Alternatively, and this IMO would be the correct solution, patch the sources, and replace every occurrence of #ifdef WIN32 or #if defined(WIN32) with #ifdef _WIN32. The macro _WIN32 is always predefined in Win32 and Win64, but the WIN32 is not.
Well, technically you'd have to differentiate each occurence if the issue is about being a Windows system or about being a MSVC compiler (there is a GCC compiler for Windows). And then use _WIN32 for the system dependencies and _MSC_VER for the compiler ones.
And then, if you feel like it, send a patch to the Codeplex project.
UPDATE
About the linker error, that should be easy to fix: just add the necessary "*.lib" file or files to the project. You can add them to the Linker Property Pageof the project.
Additionally what you did with .lib and .h, you need to keep .dll in either in, System32 dir, or in same dir where you have exe.
Answers to this question may help you understand better.

Does crtdbg.h conflict with DirectX?

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.