src/video/windowsrt/DirectXHelper.h
author David Ludwig <dludwig@pobox.com>
Sat, 27 Oct 2012 21:20:00 -0400
changeset 8322 839cd578a474
child 8384 bc7a52629e1e
permissions -rw-r--r--
WinRT: moved contents of platform-specific SDLmain into SDL.dll, where it should probably have been in the first place
     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 }