首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在DX11应用程序中使用DirectXHelper.h会导致Visual 2015中的“命名空间/未找到类”错误

在DX11应用程序中使用DirectXHelper.h会导致Visual 2015中的“命名空间/未找到类”错误
EN

Stack Overflow用户
提问于 2017-10-27 21:19:27
回答 1查看 477关注 0票数 0

我正在尝试遵循以下DirectX 11教程:https://learn.microsoft.com/en-us/windows/uwp/gaming/setting-up-directx-resources

但是,我不得不在网上找到DirectXHelper.h。有几个不同的版本,但这是我发现的最小的版本。

问题是,当我尝试使用它进行编译时,我会得到以下错误:

代码语言:javascript
复制
C2653   'Platform': is not a class or namespace name    
C3861   'CreateException': identifier not found     
C2039   'Storage': is not a member of 'Windows'     
C2871   'Storage': a namespace with this name does not exist    
C3083   'ApplicationModel': the symbol to the left of a '::' must be a type 
C3083   'Package': the symbol to the left of a '::' must be a type  
C2039   'Current': is not a member of 'Windows'     
C2065   'Current': undeclared identifier    

我不知道该做什么,也不知道我需要包括什么。当我在寻找

平台:异常::CreateException(Hr)I在C:\程序文件(X86)\MICROSOFT VISUAL STUDIO 14.0\VC\LIB\STORE\REFERENCES\PLATFORM.WINMD中坐立不安

我不知道我该怎么提这个。

代码语言:javascript
复制
//DirectXHelper.h
#pragma once

#include <ppltasks.h>   // For create_task

namespace DX
{
    inline void ThrowIfFailed(HRESULT hr)
    {
        if (FAILED(hr))
        {
            // Set a breakpoint on this line to catch Win32 API errors.
            throw Platform::Exception::CreateException(hr);
        }
    }

    // Function that reads from a binary file asynchronously.
    inline Concurrency::task<std::vector<byte>> ReadDataAsync(const std::wstring& filename)
    {
        using namespace Windows::Storage;
        using namespace Concurrency;

        auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;

        return create_task(folder->GetFileAsync(Platform::StringReference(filename.c_str()))).then([](StorageFile^ file)
        {
            return FileIO::ReadBufferAsync(file);
        }).then([](Streams::IBuffer^ fileBuffer) -> std::vector<byte>
        {
            std::vector<byte> returnBuffer;
            returnBuffer.resize(fileBuffer->Length);
            Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(Platform::ArrayReference<byte>(returnBuffer.data(), fileBuffer->Length));
            return returnBuffer;
        });
    }

    // Converts a length in device-independent pixels (DIPs) to a length in physical pixels.
    inline float ConvertDipsToPixels(float dips, float dpi)
    {
        static const float dipsPerInch = 96.0f;
        return floorf(dips * dpi / dipsPerInch + 0.5f); // Round to nearest integer.
    }
}

注意:我尝试将它构建为Win32控制台应用程序和Win32应用程序,也出现了相同的错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-28 06:37:33

该版本的ThrowIfFailed假设您正在使用C++/CX构建一个UWP应用程序(a.k.a )。/ZW)。本教程假设您使用的是Windows10上的DirectX 11应用程序模板作为您的起点。

您可以编写一个更通用的C++作为(使用/EHsc):

代码语言:javascript
复制
#include <exception>

namespace DX
{
    inline void ThrowIfFailed(HRESULT hr)
    {
        if (FAILED(hr))
        {
            // Set a breakpoint on this line to catch DirectX API errors
            throw std::exception();
        }
    }
}

有关此助手的更多信息,请参见ThrowIfFailed

为Win32桌面应用程序工作的Win32助手的一个版本可以找到这里

ConvertDipsToPixels只适用于UWP应用程序。

您应该看看DirectX Tool Kit 教程,它支持Win32桌面应用程序、UWP应用程序、Windows 8.x和Xbox应用程序。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46983546

复制
相关文章

相似问题

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