c++ - 如何在我的项目中同时包含wincodec.h和d3dx10.h(或d3dx11)文件

标签 c++ compiler-errors direct3d wic

我尝试将wincodec.h包含在我的项目中,但是如果我尝试编译它,它将给我错误,我的项目中没有任何其他头文件或cpp文件。
我的代码(为了使问题更简单而进行了编辑):

#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;
}
这是我得到的错误;
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)

所有这些错误来自wincodec.h文件。
我也尝试从Linker> Input> Additional Dependencies包含库windowscodecs.lib,但是仍然有相同的错误,因此我从那里删除了它,现在我将其包含在源代码中。
谁知道为什么我会出现这些错误,我该如何解决?
我使用Visual Studio 2019(v142),Windows SDK 10,ISO C++ 17。
作为x64版本发行。
子系统:Windows(/SUBSYSTEM:WINDOWS)
第1次编辑:
我才发现问题!
在库目录中,我具有以下路径: C:\ Program Files(x86)\ Microsoft DirectX SDK(2010年6月)\ include ,如果我将其删除,则可以正常运行。
现在的问题是那里没有此路径,我无法使用D3D部分所需的2个 header :d3dx10.h和d3dx11.h。
任何想法现在如何解决这个问题?
第2次编辑:
因此,我现在将库目录更改为:$(VC_IncludePath);$(WindowsSDK_IncludePath);$(DXSDK_DIR)/include并且只有此错误消失了:错误C3646'PixelFormat':未知的覆盖说明符

最佳答案

您遇到的基本问题是旧版DirectX SDK包含一些与Windows SDK“重叠”的 header 。对于Windows 7及更低版本的Visual Studio 2010/Windows SDK,DirectX SDK中的 header 是较新的,但自Windows 8的Windows SDK以来,并不是这样。VS 2019 v142使用Windows 10 SDK(17763)或更高版本。
Windows 8 SDK和Windows 10 SDK已包含大量的“DirectX”内容,包括最新的DXGI,Direct3D 9,Direct3D 10,Direct3D 11,Direct3D 12和D3DCompiler header /库。
Windows 8 SDK和Windows 10 SDK不包含D3DX9,D3DX10或D3DX11实用程序 header /库。这些组件已弃用。
要变通解决此问题,您需要:
(a)确保DXSDK的include/libs路径在VC++目录中的其他路径之后。
(b)在包含旧版“d3dx10.h”或“d3dx11.h” header 之前,显式包括Direct3D和DXGI header 。如果您依靠'd3dx10.h`或'd3dx11.h' header ,则它将始终使用旧版本:

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

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

参见Microsoft Docsthis 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'.

关于c++ - 如何在我的项目中同时包含wincodec.h和d3dx10.h(或d3dx11)文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65105931/

相关文章:

objective-c - 在 block 内使用指向 block 外声明的对象的指针

c++ - VC++ : Weird compiler errors

c++ - ID3D10Device::RSSetState 每帧调用?

c++ - 如何选择 DirectX 像素格式?

c++ - 在 lambda 函数语法中, 'capture list' 有什么用途?

c++ - 类工厂创建派生类 C++

python - Python 中是否可以使用 C++ 样式的日志记录宏?

c++ - 在 OpenCV 中乘以矩阵的 SVD 分量

c++ - 为 std::string 释放内存的异常(尝试在 UE4 中使用 YOLO/Darknet)

windows-10 - 在windows10中开发dx应用还需要DirectX SDK吗?