奇怪的错误C2146和C4430在d3d11shader.h在VS2012

Weird Error C2146 and C4430 in d3d11shader.h in VS2012

本文关键字:d3d11shader VS2012 C4430 错误 C2146      更新时间:2023-10-16

所以我是按照书上的说明来创建一个d3d对象。然而,当我试图编译代码时,它在d3d11shader.h中给了我一些奇怪的错误。

在d3dshader.h内,

#include "d3dcommon.h" 
//other stuff
typedef struct _D3D11_SIGNATURE_PARAMETER_DESC
{
    LPCSTR                      SemanticName;   
    UINT                        SemanticIndex;  
    UINT                        Register;       
    D3D_NAME                    SystemValueType;
    D3D_REGISTER_COMPONENT_TYPE ComponentType;  
    BYTE                        Mask;                      
    BYTE                        ReadWriteMask;  
    UINT                        Stream;        
    D3D_MIN_PRECISION           MinPrecision;  //Errors here
} D3D11_SIGNATURE_PARAMETER_DESC;
对细节:

(1) Error   29  error C2146: syntax error : missing ';' before identifier 'MinPrecision'    c:program files (x86)windows kits8.0includeumd3d11shader.h    54
(2) Error   30  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:program files (x86)windows kits8.0includeumd3d11shader.h    54

这很奇怪,因为d3dcommon.h和d3d11shader.h文件都是在Windows SDK和DirectX SDK中定义的,所以我不能改变它们中的任何东西。谁能告诉我怎么修理它?

以下是我的Source.cpp中的代码,这些代码直接从Frank Luna的《3D Game Programming with DirectX11》一书中复制。

#include "d3dApp.h"//This header file is provided by the book

class InitDirect3DApp : public D3DApp
{
public:
    InitDirect3DApp(HINSTANCE hInstance);
    ~InitDirect3DApp();
    bool Init();
    void OnResize();
    void UpdateScene(float dt);
    void DrawScene(); 
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
               PSTR cmdLine, int showCmd)
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
    InitDirect3DApp theApp(hInstance);
    if( !theApp.Init() )
        return 0;
    return theApp.Run();
}
 Init Direct3DApp::InitDirect3DApp(HINSTANCE hInstance)
  : D3DApp(hInstance) 
{
 }
 InitDirect3DApp::~InitDirect3DApp()
{
}
 bool InitDirect3DApp::Init()
{
    if(!D3DApp::Init())
        return false;
    return true;
}
 void InitDirect3DApp::OnResize()
{
    D3DApp::OnResize();
}
void InitDirect3DApp::UpdateScene(float dt)
{
}
void InitDirect3DApp::DrawScene()
{
    assert(md3dImmediateContext);
    assert(mSwapChain);
    md3dImmediateContext->ClearRenderTargetView(mRenderTargetView,     reinterpret_cast<const float*>(&Colors::Blue));
    md3dImmediateContext->ClearDepthStencilView(mDepthStencilView, D3D11_CLEAR_DEPTH|D3D11_CLEAR_STENCIL, 1.0f, 0);
    HR(mSwapChain->Present(0, 0));
}

我注意到的另一件奇怪的事情是,有时当我去D3D_MIN_PRECISION的定义,它引导我到d3dcommon.h, d3dcommon.h中的代码根本没有突出显示。Visual Studio会自动为所有其他文件高亮显示,但这个文件除外。所以我只是假设它不识别代码在这个特定的头文件的一些时间。

而且,当我刚才试图编译代码时,除了前面两个错误之外,还会弹出另一个错误:

   31   IntelliSense: identifier "D3D_MIN_PRECISION" is undefined   c:Program Files (x86)Windows Kits8.0Includeumd3d11shader.h    54

只是为了你的信息,我在windows 8.1机器上使用vs2012。非常感谢!

你的问题很可能是你混合了Windows 8。x SDK和旧的DirectX SDK标头不正确。

历史上,你会设置INCLUDE和LIB路径,使DXSDK_DIR是第一个,但这只在DirectX SDK头是当前的情况下才有效。现在它们已经过时了,你需要在DXSDK_DIR之前使用WindowsSdkDir(假设你需要使用D3DX这样的东西,这是过时的,只在传统的DirectX SDK中可用;否则你根本不需要它)。

使用VS 2012的"v110"或VS 2013的"v120"平台工具集,如果你还需要使用DirectX SDK,你可以使用vc++的目录设置为Include和Lib:

$(IncludePath);$(DXSDK_DIR)Include   
$(LibraryPath);$(DXSDK_DIR)Lib<x86 or x64> 

请参阅MSDN, Living Without D3DX, XInput, and XAudio

顺便说一句,如果你试图使用VS 2012的"v110_xp"或VS 2013的"v120_xp"平台工具集,它的工作方式更像以前,会使用传统的顺序。请看这篇博文。

$(DXSDK_DIR)Include;$(IncludePath);
$(DXSDK_DIR)Lib<x86 or x64>;$(LibraryPath)