D3D11 D3DX11CreateEffectFromMemory returns E_NOITERFACE

D3D11 D3DX11CreateEffectFromMemory returns E_NOITERFACE

我正在阅读 Frank Luna 撰写的《DirectX 11 编程简介》一书,但在使用 Effects11 时遇到了问题。

void BoxApp::BuildFX()
{

    DWORD shaderFlags = 0;
#if defined( DEBUG ) || defined( _DEBUG )
    shaderFlags |= D3D10_SHADER_DEBUG;
    shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

    ID3D10Blob* compiledShader = 0;
    ID3D10Blob* compilationMsgs = 0;
    HRESULT hr = D3DX11CompileFromFile(L"FX/color.fx", 0, 0, 0, "fx_5_0", shaderFlags, 
        0, 0, &compiledShader, &compilationMsgs, 0);

    // compilationMsgs can store errors or warnings.
    if( compilationMsgs != 0 )
    {
        MessageBoxA(0, (char*)compilationMsgs->GetBufferPointer(), 0, 0);
        ReleaseCOM(compilationMsgs);
    }

    // Even if there are no compilationMsgs, check to make sure there were no other errors.
    if(FAILED(hr))
    {
        DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX11CompileFromFile", true);
    }

    HR(D3DX11CreateEffectFromMemory(compiledShader->GetBufferPointer(), compiledShader->GetBufferSize(), 
        0, md3dDevice, &mFX));

    // Done with compiled shader.
    ReleaseCOM(compiledShader);

    mTech    = mFX->GetTechniqueByName("ColorTech");
    mfxWorldViewProj = mFX->GetVariableByName("gWorldViewProj")->AsMatrix();
}

我正在使用此代码加载我的效果文件。问题是我在 D3DX11CreateEffectFromMemory 处收到 E_NOINTERFACE 错误。有趣的是,运行 书中的示例成功调用了该函数,并且它使用了完全相同的静态库(d3dx11effect.h 和 Effect11d.lib)。我什至尝试先编译效果然后加载它,但问题仍然存在。

提前感谢您的帮助。

我发现这个人 (E_NOINTERFACE result from D3DX11CreateEffectFromMemory) 有完全相同的问题,他通过降级到 VS2010 解决了这个问题。我对任何其他解决方案都非常满意。

对于您的具体问题,问题在于您尝试将使用 VS 2010 构建的静态 C++ 库与较新版本的 Visual C++ 工具集一起使用,这可能会导致问题。解决方案是使用您当前的工具集从源代码构建效果库。

Direct3D 11 效果库的最新完整源代码也可在 CodePlex & GitHub. If you are using VS 2013, you can get a copy for Windows desktop apps from NuGet 上获得。

不幸的是,Frank 的书是在开发人员获取 DirectX 的最新 headers、库、工具和示例以及旧版 DirectX SDK 弃用的方式发生重大转变之前编写和出版的。另见 MSDN and this blog post for some details. I've made some specific notes about Frank's books here

您没有明确提及,但我假设您使用的是 VS 2012 或 VS 2013,其中包含 Windows 8.x SDK。您可以将旧版 DirectX SDK 与此工具集一起使用,并调整一些项目文件,但您应该记住,所有版本的 D3DX9、D3DX10 和 D3DX11 都已弃用。有关 Direct3D 11 的替换,请参阅 Living without D3DX

另见 DirectX SDKs of a certain age, DirectX SDK Samples Catalog, and DirectX SDK Tools Catalog

使用 VS2010 从 DXSDK 示例编译源代码

C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Samples\C++\Effects11\Effects11_2008.sln

复制 D3DX11EffectsD.lib 到你的 lib 路径,并链接它。

项目 属性 -> 配置属性 -> 常规 -> 平台工具集 -> 将 "Visual studio 2013 (v120)" 更改为 "Visual Studio 2013 - Windows XP (v120_xp)"

希望这对您有所帮助。