首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >奇怪的错误C2146和C4430在d3d11shader.h中VS2012

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

Stack Overflow用户
提问于 2014-08-07 03:26:01
回答 1查看 1.2K关注 0票数 1

因此,我按照一本书上的说明创建了一个d3d对象。但是,当我试图编译代码时,d3d11shader.h中出现了一些奇怪的错误。

在d3dshader.h里面,

代码语言:javascript
复制
#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;

详情:

代码语言:javascript
复制
(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

这很奇怪,因为在Windows和DirectX SDK中都定义了d3dcommon.h和d3d11shader.h文件,所以我不能在它们中更改任何内容。有人能告诉我怎么修吗?如有任何意见,敬请于此。

这是我的Source.cpp中的代码,它是直接从弗兰克露娜的“3D游戏编程与DirectX11”一书中抄袭而来的。

代码语言:javascript
复制
#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会自动对所有其他文件进行高亮显示,但对于此文件则不会。所以我只是假设它不识别这个特定的头文件中的代码。

此外,当我刚才试图编译代码时,除了前两个错误之外,还出现了另一个错误:

代码语言:javascript
复制
   31   IntelliSense: identifier "D3D_MIN_PRECISION" is undefined   c:\Program Files (x86)\Windows Kits\8.0\Include\um\d3d11shader.h    54

仅供您参考,我在Windows8.1机器上使用vs2012。非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-08 19:14:28

您的问题很可能是将Windows8.xSDK和遗留DirectX SDK头错误地混在一起。

历史上,您会设置包含路径和LIB路径,以便DXSDK_DIR是第一位的,但只有当DirectX头当前时才能工作。现在它们已经过时了,您需要在WindowsSdkDir之前使用DXSDK_DIR (假设您需要使用只在遗留DirectX SDK中可用的D3DX之类的东西;否则根本不需要它)。

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

代码语言:javascript
复制
$(IncludePath);$(DXSDK_DIR)Include   
$(LibraryPath);$(DXSDK_DIR)Lib\<x86 or x64> 

MSDN无D3DX生活XInputXAudio

顺便说一句,如果你试图使用VS 2012的"v110_xp“或2013年的"v120_xp”平台工具集,它的工作方式会更像以前的样子,并且会使用传统的顺序。参见博客文章。

代码语言:javascript
复制
$(DXSDK_DIR)Include;$(IncludePath);
$(DXSDK_DIR)Lib\<x86 or x64>;$(LibraryPath)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25173616

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档