Path: blob/master/samples/wp8/OcvRotatingCube/PhoneXamlDirect3DApp1/PhoneXamlDirect3DApp1Comp/DirectXHelper.h
16349 views
#pragma once12#include <wrl/client.h>3#include <ppl.h>4#include <ppltasks.h>56namespace DX7{8inline void ThrowIfFailed(HRESULT hr)9{10if (FAILED(hr))11{12// Set a breakpoint on this line to catch Win32 API errors.13throw Platform::Exception::CreateException(hr);14}15}1617// Function that reads from a binary file asynchronously.18inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)19{20using namespace Windows::Storage;21using namespace Concurrency;2223auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;2425return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file)26{27return file->OpenReadAsync();28}).then([] (Streams::IRandomAccessStreamWithContentType^ stream)29{30unsigned int bufferSize = static_cast<unsigned int>(stream->Size);31auto fileBuffer = ref new Streams::Buffer(bufferSize);32return stream->ReadAsync(fileBuffer, bufferSize, Streams::InputStreamOptions::None);33}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^34{35auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);36Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);37return fileData;38});39}40}4142