|
//Copyright (c) Microsoft Corporation. All rights reserved.
#include "StdAfx.h"
#include "DirectObject.h"
#include "DirectUnknown.h"
#include "DirectHelpers.h"
#include "CommonUtils.h"
using namespace Microsoft::WindowsAPICodePack::DirectX;
using namespace Microsoft::WindowsAPICodePack::DirectX::DXGI;
using namespace Microsoft::WindowsAPICodePack::DirectX::Direct2D1;
using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D;
generic <typename T> where T : DirectUnknown
T DirectHelpers::CreateIUnknown(System::IntPtr nativePointer)
{
return safe_cast<T>(CommonUtils::CreateIUnknownWrapper<T>(static_cast<IUnknown*>(nativePointer.ToPointer())));
}
generic <typename T> where T : DirectObject
T DirectHelpers::CreateInterface(System::IntPtr nativePointer)
{
T wrapper = safe_cast<T>( Activator::CreateInstance(T::typeid, true) );
(safe_cast<DirectObject^>(wrapper))->Attach(nativePointer.ToPointer());
return wrapper;
}
Exception^ DirectHelpers::GetExceptionForHResult(int hr)
{
return CommonUtils::GetExceptionForHR(static_cast<HRESULT>(hr));
}
Exception^ DirectHelpers::GetExceptionForErrorCode(ErrorCode errorCode)
{
return CommonUtils::GetExceptionForHR(static_cast<HRESULT>(errorCode));
}
void DirectHelpers::ThrowExceptionForHResult(int hr)
{
int val = static_cast<HRESULT>(hr);
if (SUCCEEDED(val))
return;
else
throw CommonUtils::GetExceptionForHR(val);
}
void DirectHelpers::ThrowExceptionForErrorCode(ErrorCode errorCode)
{
int val = static_cast<HRESULT>(errorCode);
if (SUCCEEDED(val))
return;
else
throw CommonUtils::GetExceptionForHR(val);
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
John graduated from the University of South Australia in 1997 with a Bachelor of Electronic Engineering Degree, and since then he has worked on hardware and software in many fields including Aerospace, Defence, and Medical giving him over 10 of years experience in C++ and C# programming. In 2009 John Started his own contracting company doing business between Taiwan and Australia.