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/*
     1 #pragma once
     2 
     3 #include <wrl/client.h>
     4 #include <ppl.h>
     5 #include <ppltasks.h>
     6 
     7 namespace DX
     8 {
     9     inline void ThrowIfFailed(HRESULT hr)
    10     {
    11         if (FAILED(hr))
    12         {
    13             // Set a breakpoint on this line to catch Win32 API errors.
    14             throw Platform::Exception::CreateException(hr);
    15         }
    16     }
    17 
    18     // Function that reads from a binary file asynchronously.
    19     inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
    20     {
    21         using namespace Windows::Storage;
    22         using namespace Concurrency;
    23         
    24         auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
    25         
    26         return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
    27         {
    28             return FileIO::ReadBufferAsync(file);
    29         }).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
    30         {
    31             auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
    32             Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
    33             return fileData;
    34         });
    35     }
    36 }