src/video/windowsrt/DirectXHelper.h
changeset 8384 bc7a52629e1e
parent 8322 839cd578a474
child 8397 8cd319461894
equal deleted inserted replaced
8383:1f415392ccf0 8384:bc7a52629e1e
     4 #include <ppl.h>
     4 #include <ppl.h>
     5 #include <ppltasks.h>
     5 #include <ppltasks.h>
     6 
     6 
     7 namespace DX
     7 namespace DX
     8 {
     8 {
     9 	inline void ThrowIfFailed(HRESULT hr)
     9     inline void ThrowIfFailed(HRESULT hr)
    10 	{
    10     {
    11 		if (FAILED(hr))
    11         if (FAILED(hr))
    12 		{
    12         {
    13 			// Set a breakpoint on this line to catch Win32 API errors.
    13             // Set a breakpoint on this line to catch Win32 API errors.
    14 			throw Platform::Exception::CreateException(hr);
    14             throw Platform::Exception::CreateException(hr);
    15 		}
    15         }
    16 	}
    16     }
    17 
    17 
    18 	// Function that reads from a binary file asynchronously.
    18     // Function that reads from a binary file asynchronously.
    19 	inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
    19     inline Concurrency::task<Platform::Array<byte>^> ReadDataAsync(Platform::String^ filename)
    20 	{
    20     {
    21 		using namespace Windows::Storage;
    21         using namespace Windows::Storage;
    22 		using namespace Concurrency;
    22         using namespace Concurrency;
    23 		
    23         
    24 		auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
    24         auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
    25 		
    25         
    26 		return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
    26         return create_task(folder->GetFileAsync(filename)).then([] (StorageFile^ file) 
    27 		{
    27         {
    28 			return FileIO::ReadBufferAsync(file);
    28             return FileIO::ReadBufferAsync(file);
    29 		}).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
    29         }).then([] (Streams::IBuffer^ fileBuffer) -> Platform::Array<byte>^ 
    30 		{
    30         {
    31 			auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
    31             auto fileData = ref new Platform::Array<byte>(fileBuffer->Length);
    32 			Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
    32             Streams::DataReader::FromBuffer(fileBuffer)->ReadBytes(fileData);
    33 			return fileData;
    33             return fileData;
    34 		});
    34         });
    35 	}
    35     }
    36 }
    36 }