how to include both wincodec.h and d3dx10.h (or d3dx11) files in my project

1.6k Views Asked by At

i try to include wincodec.h in my project but it gives me errors if i try compile it, i dont have any other header or cpp file in my project.

my code (EDITED to make it more simple to understand the issue):

#pragma comment (lib, "windowscodecs.lib")

//it doesn't matter if include here also the Windows.h

//[about the 1st EDIT] i don't include any d3dx (10 or 11) headers here! However the compiler still gives me errors!!!

#include <wincodec.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    return 0;
}

and here are the errors i get;

Error   C3646   'PixelFormat': unknown override specifier

Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int

Error   C2061   syntax error: identifier 'DXGI_JPEG_AC_HUFFMAN_TABLE' (same error also for DXGI_JPEG_DC_HUFFMAN_TABLE and DXGI_JPEG_QUANTIZATION_TABLE)

All these errors coming from wincodec.h file. Also i tried to include the library windowscodecs.lib from Linker>Input>Additional Dependencies but still had the same errors so i removed from there and now i include it here in source. Anyone knows why i get these errors and how can i fix it?

I use visual studio 2019 (v142), windows sdk 10, iso c++ 17. Builting as Release, x64. SubSystem: Windows(/SUBSYSTEM:WINDOWS)

1st EDIT: I just found the problem! In Library Directories i had this path: C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include, if i remove it, it built fine.

Now the problem is without have this path there, i can't use 2 headers that i need for D3D part: d3dx10.h and d3dx11.h.

Any idea how to solve this problem now?

2nd EDIT: So, i now changed Library Directories to this: $(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)/include and only this error disappeared: Error C3646 'PixelFormat': unknown override specifier

1

There are 1 best solutions below

0
On

The basic issue you are encountering is that the legacy DirectX SDK contains some headers that 'overlap' with the Windows SDK. For Visual Studio 2010 / Windows SDK for Windows 7 and before, those headers in the DirectX SDK were newer, but that's not been true since the Windows SDK for Windows 8. VS 2019 v142 is using the Windows 10 SDK (17763) or later.

The Windows 8 SDK and Windows 10 SDK already include the bulk of the "DirectX" content including the latest DXGI, Direct3D 9, Direct3D 10, Direct3D 11, Direct3D 12, and D3DCompiler headers/libs.

The Windows 8 SDK and Windows 10 SDK does not contain the D3DX9, D3DX10, or D3DX11 utility headers/libraries. Those components are deprecated.

To workaround this issue, you need to:

(a) make sure the DXSDK include/libs paths are after the other paths in your VC++ Directories.

(b) explicitly include the Direct3D and DXGI headers before the legacy 'd3dx10.h' or 'd3dx11.h' headers are included. If you rely on the 'd3dx10.h` or 'd3dx11.h' header, then it will always be pulling in the old version:

#include <dxgi.h>
#include <d3d10.h>
#include <d3d11.h>

#include <d3dx10.h>
#include <d3dx11.h>

See Microsoft Docs and this blog post

Ideally you'd remove all use of the deprecated DirectX SDK and not use D3DX10 or D3DX11 at all. You can find a bunch of open source replacements listed here.

Note that if you use the v141_xp toolset for Windows XP support, that actually uses a Windows 7.1A SDK which is before DirectX was integrated and in that case, the legacy DirectX SDK headers are 'newer'.

UPDATE: Another option to using the D3DX library without having these header conflicts is to use the Microsoft.DXSDK.D3DX NuGet package instead of the legacy DirectX SDK. Ideally you'd move to those open source replacements instead as D3DX9/10/11 is still quite old.