src/video/windowsrt/DirectXHelper.h
author David Ludwig <dludwig@pobox.com>
Sun, 28 Oct 2012 20:47:33 -0400
changeset 8332 ea83d191cc17
parent 8322 839cd578a474
child 8384 bc7a52629e1e
permissions -rw-r--r--
WinRT: added mouse button event support
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@8322
     9
	inline void ThrowIfFailed(HRESULT hr)
dludwig@8322
    10
	{
dludwig@8322
    11
		if (FAILED(hr))
dludwig@8322
    12
		{
dludwig@8322
    13
			// Set a breakpoint on this line to catch Win32 API errors.
dludwig@8322
    14
			throw Platform::Exception::CreateException(hr);
dludwig@8322
    15
		}
dludwig@8322
    16
	}
dludwig@8322
    17
dludwig@8322
    18
	// Function that reads from a binary file asynchronously.
dludwig@8322
    19
	inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
dludwig@8322
    20
	{
dludwig@8322
    21
		using namespace Windows::Storage;
dludwig@8322
    22
		using namespace Concurrency;
dludwig@8322
    23
		
dludwig@8322
    24
		auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
dludwig@8322
    25
		
dludwig@8322
    26
		return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
dludwig@8322
    27
		{
dludwig@8322
    28
			return FileIO::ReadBufferAsync(file);
dludwig@8322
    29
		}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
dludwig@8322
    30
		{
dludwig@8322
    31
			auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
dludwig@8322
    32
			Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
dludwig@8322
    33
			return fileData;
dludwig@8322
    34
		});
dludwig@8322
    35
	}
dludwig@8322
    36
}