src/video/windowsrt/DirectXHelper.h
author David Ludwig <dludwig@pobox.com>
Tue, 08 Jan 2013 23:11:22 -0500
changeset 8384 bc7a52629e1e
parent 8322 839cd578a474
child 8397 8cd319461894
permissions -rw-r--r--
WinRT: converted tabs to spaces in src/video/windowsrt/*
dludwig@8322
     1
#pragma once
dludwig@8322
     2
dludwig@8322
     3
#include <wrl/client.h>
dludwig@8322
     4
#include <ppl.h>
dludwig@8322
     5
#include <ppltasks.h>
dludwig@8322
     6
dludwig@8322
     7
namespace DX
dludwig@8322
     8
{
dludwig@8384
     9
    inline void ThrowIfFailed(HRESULT hr)
dludwig@8384
    10
    {
dludwig@8384
    11
        if (FAILED(hr))
dludwig@8384
    12
        {
dludwig@8384
    13
            // Set a breakpoint on this line to catch Win32 API errors.
dludwig@8384
    14
            throw Platform::Exception::CreateException(hr);
dludwig@8384
    15
        }
dludwig@8384
    16
    }
dludwig@8322
    17
dludwig@8384
    18
    // Function that reads from a binary file asynchronously.
dludwig@8384
    19
    inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
dludwig@8384
    20
    {
dludwig@8384
    21
        using namespace Windows::Storage;
dludwig@8384
    22
        using namespace Concurrency;
dludwig@8384
    23
        
dludwig@8384
    24
        auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
dludwig@8384
    25
        
dludwig@8384
    26
        return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
dludwig@8384
    27
        {
dludwig@8384
    28
            return FileIO::ReadBufferAsync(file);
dludwig@8384
    29
        }).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
dludwig@8384
    30
        {
dludwig@8384
    31
            auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
dludwig@8384
    32
            Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
dludwig@8384
    33
            return fileData;
dludwig@8384
    34
        });
dludwig@8384
    35
    }
dludwig@8322
    36
}