我正在尝试遵循以下DirectX 11教程:https://learn.microsoft.com/en-us/windows/uwp/gaming/setting-up-directx-resources
但是,我不得不在网上找到DirectXHelper.h。有几个不同的版本,但这是我发现的最小的版本。
问题是,当我尝试使用它进行编译时,我会得到以下错误:
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中坐立不安
我不知道我该怎么提这个。
//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应用程序,也出现了相同的错误
发布于 2017-10-28 06:37:33
该版本的ThrowIfFailed假设您正在使用C++/CX构建一个UWP应用程序(a.k.a )。/ZW)。本教程假设您使用的是Windows10上的DirectX 11应用程序模板作为您的起点。
您可以编写一个更通用的C++作为(使用/EHsc):
#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应用程序。
https://stackoverflow.com/questions/46983546
复制相似问题