在 DX11 应用程序中使用 DirectXHelper.h 导致 'namespace/class not found' 错误 Visual Studio 2015
Using DirectXHelper.h in DX11 application causes 'namespace/class not found' errors in Visual Studio 2015
我正在尝试按照此处找到的 DirectX 11 教程进行操作:https://docs.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
我不确定要做什么或需要包括什么。当我搜索
Platform::Exception::CreateException(hr) 我发现了
C:\程序文件 (X86)\微软 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 应用程序,出现了同样的错误
该版本的 ThrowIfFailed
假设您正在使用 C++/CX 构建 UWP 应用程序 (a.k.a。/ZW
)。该教程假定您在 Windows 10 上使用适用于 UWP 平台的 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 桌面应用程序的 ReadDataAsync
助手版本 here。
ConvertDipsToPixels
只有 UWP 应用程序才需要。
You should take a look at DirectX Tool Kit tutorials which supports Win32 desktop apps, UWP apps, Windows phone 8.x, and Xbox One XDK apps.
我正在尝试按照此处找到的 DirectX 11 教程进行操作:https://docs.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
我不确定要做什么或需要包括什么。当我搜索
Platform::Exception::CreateException(hr) 我发现了
C:\程序文件 (X86)\微软 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 应用程序,出现了同样的错误
该版本的 ThrowIfFailed
假设您正在使用 C++/CX 构建 UWP 应用程序 (a.k.a。/ZW
)。该教程假定您在 Windows 10 上使用适用于 UWP 平台的 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 桌面应用程序的 ReadDataAsync
助手版本 here。
ConvertDipsToPixels
只有 UWP 应用程序才需要。
You should take a look at DirectX Tool Kit tutorials which supports Win32 desktop apps, UWP apps, Windows phone 8.x, and Xbox One XDK apps.