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

时间:2014-08-07 03:26:02

标签: c++ visual-studio-2012 directx direct3d

所以我按照书上的说明创建了一个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 kits\8.0\include\um\d3d11shader.h    54
(2) Error   30  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files (x86)\windows kits\8.0\include\um\d3d11shader.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 Kits\8.0\Include\um\d3d11shader.h    54

仅供参考,我在Windows 8.1机器上使用vs2012。非常感谢!

1 个答案:

答案 0 :(得分:0)

您的问题很可能是您错误地混合了Windows 8.x SDK和旧版DirectX SDK标头。

以前,您会设置INCLUDE和LIB路径,以便DXSDK_DIR是第一个,但只有当DirectX SDK标头是最新的时才有效。现在它们已经过时了,你需要在DXSDK_DIR之前使用WindowsSdkDir(假设你需要使用D3DX之类的东西,这种东西已被弃用,仅在传统的DirectX SDK中可用;否则根本不需要它。) / p>

使用VS 2012的“v110”或VS 2013的“v120”平台工具集,如果您还需要使用DirectX SDK,则可以使用包含和库的VC ++目录设置:

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

请参阅MSDNLiving Without D3DXXInputXAudio

顺便说一下,如果您尝试使用VS 2012的“v110_xp”或VS 2013的“v120_xp”平台工具集,它的工作方式与过去相似,并会使用传统的顺序。请参阅this博文。

$(DXSDK_DIR)Include;$(IncludePath);
$(DXSDK_DIR)Lib\<x86 or x64>;$(LibraryPath)
相关问题