From 9328fa902887c15a58c95bfdf69cfa28e9a012c2 Mon Sep 17 00:00:00 2001 From: Brad Hughes Date: Sat, 19 Mar 2016 21:43:27 -0400 Subject: [PATCH] Fix VS Build issue for WRL ComPtr --- 3rdparty/compat/winsdk-override/wrl/client.h | 308 +++++++++++++++++++ scripts/src/osd/modules.lua | 6 + src/osd/modules/input/input_dinput.cpp | 2 +- 3 files changed, 315 insertions(+), 1 deletion(-) create mode 100644 3rdparty/compat/winsdk-override/wrl/client.h diff --git a/3rdparty/compat/winsdk-override/wrl/client.h b/3rdparty/compat/winsdk-override/wrl/client.h new file mode 100644 index 00000000000..5e3e0c35fb1 --- /dev/null +++ b/3rdparty/compat/winsdk-override/wrl/client.h @@ -0,0 +1,308 @@ +/** + * This file has no copyright assigned and is placed in the Public Domain. + * This file is part of the mingw-w64 runtime package. + * No warranty is given; refer to the file DISCLAIMER.PD within this package. + */ + +#ifndef _WRL_CLIENT_H_ +#define _WRL_CLIENT_H_ + +#include +#include +/* #include */ +#include + +/* #include */ +#include + +namespace Microsoft { + namespace WRL { + namespace Details { + template class ComPtrRefBase { + protected: + T* ptr_; + + public: + typedef typename T::InterfaceType InterfaceType; + +#ifndef __WRL_CLASSIC_COM__ + operator IInspectable**() const throw() { + static_assert(__is_base_of(IInspectable, InterfaceType), "Invalid cast"); + return reinterpret_cast(ptr_->ReleaseAndGetAddressOf()); + } +#endif + + operator IUnknown**() const throw() { + static_assert(__is_base_of(IUnknown, InterfaceType), "Invalid cast"); + return reinterpret_cast(ptr_->ReleaseAndGetAddressOf()); + } + }; + + template class ComPtrRef : public Details::ComPtrRefBase { + public: + ComPtrRef(T *ptr) throw() { + ComPtrRefBase::ptr_ = ptr; + } + + operator void**() const throw() { + return reinterpret_cast(ComPtrRefBase::ptr_->ReleaseAndGetAddressOf()); + } + + operator T*() throw() { + *ComPtrRefBase::ptr_ = nullptr; + return ComPtrRefBase::ptr_; + } + + operator typename ComPtrRefBase::InterfaceType**() throw() { + return ComPtrRefBase::ptr_->ReleaseAndGetAddressOf(); + } + + typename ComPtrRefBase::InterfaceType *operator*() throw() { + return ComPtrRefBase::ptr_->Get(); + } + + typename ComPtrRefBase::InterfaceType *const *GetAddressOf() const throw() { + return ComPtrRefBase::ptr_->GetAddressOf(); + } + + typename ComPtrRefBase::InterfaceType **ReleaseAndGetAddressOf() throw() { + return ComPtrRefBase::ptr_->ReleaseAndGetAddressOf(); + } + }; + + } + + template class ComPtr { + public: + typedef T InterfaceType; + + ComPtr() throw() : ptr_(nullptr) {} + ComPtr(decltype(nullptr)) throw() : ptr_(nullptr) {} + + template ComPtr(U *other) throw() : ptr_(other.ptr_) { + InternalAddRef(); + } + + ComPtr(const ComPtr &other) throw() : ptr_(other.ptr_) { + InternalAddRef(); + } + + template + ComPtr(const ComPtr &other) throw() : ptr_(other.ptr_) { + InternalAddRef(); + } + + ComPtr(ComPtr &&other) throw() : ptr_(nullptr) { + if(this != reinterpret_cast(&reinterpret_cast(other))) + Swap(other); + } + + template + ComPtr(ComPtr&& other) throw() : ptr_(other.ptr_) { + other.ptr_ = nullptr; + } + + ~ComPtr() throw() { + InternalRelease(); + } + + ComPtr &operator=(decltype(nullptr)) throw() { + InternalRelease(); + return *this; + } + + ComPtr &operator=(InterfaceType *other) throw() { + if (ptr_ != other) { + InternalRelease(); + ptr_ = other; + InternalAddRef(); + } + return *this; + } + + template + ComPtr &operator=(U *other) throw() { + if (ptr_ != other) { + InternalRelease(); + ptr_ = other; + InternalAddRef(); + } + return *this; + } + + ComPtr& operator=(const ComPtr &other) throw() { + if (ptr_ != other.ptr_) + ComPtr(other).Swap(*this); + return *this; + } + + template + ComPtr &operator=(const ComPtr &other) throw() { + ComPtr(other).Swap(*this); + return *this; + } + + ComPtr& operator=(ComPtr &&other) throw() { + ComPtr(other).Swap(*this); + return *this; + } + + template + ComPtr& operator=(ComPtr &&other) throw() { + ComPtr(other).Swap(*this); + return *this; + } + + void Swap(ComPtr &&r) throw() { + InterfaceType *tmp = ptr_; + ptr_ = r.ptr_; + r.ptr_ = tmp; + } + + void Swap(ComPtr &r) throw() { + InterfaceType *tmp = ptr_; + ptr_ = r.ptr_; + r.ptr_ = tmp; + } + + operator Details::BoolType() const throw() { + return Get() != nullptr ? &Details::BoolStruct::Member : nullptr; + } + + InterfaceType *Get() const throw() { + return ptr_; + } + + InterfaceType *operator->() const throw() { + return ptr_; + } + + Details::ComPtrRef> operator&() throw() { + return Details::ComPtrRef>(this); + } + + const Details::ComPtrRef> operator&() const throw() { + return Details::ComPtrRef>(this); + } + + InterfaceType *const *GetAddressOf() const throw() { + return &ptr_; + } + + InterfaceType **GetAddressOf() throw() { + return &ptr_; + } + + InterfaceType **ReleaseAndGetAddressOf() throw() { + InternalRelease(); + return &ptr_; + } + + InterfaceType *Detach() throw() { + T* ptr = ptr_; + ptr_ = nullptr; + return ptr; + } + + void Attach(InterfaceType *other) throw() { + if (ptr_ != other) { + InternalRelease(); + ptr_ = other; + InternalAddRef(); + } + } + + unsigned long Reset() { + return InternalRelease(); + } + + HRESULT CopyTo(InterfaceType **ptr) const throw() { + InternalAddRef(); + *ptr = ptr_; + return S_OK; + } + + HRESULT CopyTo(REFIID riid, void **ptr) const throw() { + return ptr_->QueryInterface(riid, ptr); + } + + template + HRESULT CopyTo(U **ptr) const throw() { + return ptr_->QueryInterface(__uuidof(U), reinterpret_cast(ptr)); + } + + template + HRESULT As(Details::ComPtrRef> p) const throw() { + return ptr_->QueryInterface(__uuidof(U), p); + } + + template + HRESULT As(ComPtr *p) const throw() { + return ptr_->QueryInterface(__uuidof(U), reinterpret_cast(p->ReleaseAndGetAddressOf())); + } + + HRESULT AsIID(REFIID riid, ComPtr *p) const throw() { + return ptr_->QueryInterface(riid, reinterpret_cast(p->ReleaseAndGetAddressOf())); + } + + /* + HRESULT AsWeak(WeakRef *pWeakRef) const throw() { + return ::Microsoft::WRL::AsWeak(ptr_, pWeakRef); + } + */ + protected: + InterfaceType *ptr_; + + void InternalAddRef() const throw() { + if(ptr_) + ptr_->AddRef(); + } + + unsigned long InternalRelease() throw() { + InterfaceType *tmp = ptr_; + if(!tmp) + return 0; + ptr_ = nullptr; + return tmp->Release(); + } + }; + } +} + +template +void **IID_PPV_ARGS_Helper(::Microsoft::WRL::Details::ComPtrRef pp) throw() { + static_assert(__is_base_of(IUnknown, typename T::InterfaceType), "Expected COM interface"); + return pp; +} + +namespace Windows { + namespace Foundation { + template + inline HRESULT ActivateInstance(HSTRING classid, ::Microsoft::WRL::Details::ComPtrRef instance) throw() { + return ActivateInstance(classid, instance.ReleaseAndGetAddressOf()); + } + + template + inline HRESULT GetActivationFactory(HSTRING classid, ::Microsoft::WRL::Details::ComPtrRef factory) throw() { + return RoGetActivationFactory(classid, IID_INS_ARGS(factory.ReleaseAndGetAddressOf())); + } + } +} + +namespace ABI { + namespace Windows { + namespace Foundation { + template + inline HRESULT ActivateInstance(HSTRING classid, ::Microsoft::WRL::Details::ComPtrRef instance) throw() { + return ActivateInstance(classid, instance.ReleaseAndGetAddressOf()); + } + + template + inline HRESULT GetActivationFactory(HSTRING classid, ::Microsoft::WRL::Details::ComPtrRef factory) throw() { + return RoGetActivationFactory(classid, IID_INS_ARGS(factory.ReleaseAndGetAddressOf())); + } + } + } +} + +#endif diff --git a/scripts/src/osd/modules.lua b/scripts/src/osd/modules.lua index 5cef56772a3..618a90a968e 100644 --- a/scripts/src/osd/modules.lua +++ b/scripts/src/osd/modules.lua @@ -91,6 +91,12 @@ function osdmodulesbuild() MAME_DIR .. "3rdparty/winpcap/Include", MAME_DIR .. "3rdparty/compat/mingw", } + + if _OPTIONS["MODERN_WIN_API"]~="1" then + includedirs { + MAME_DIR .. "3rdparty/compat/winsdk-override", + } + end end if _OPTIONS["NO_OPENGL"]=="1" then diff --git a/src/osd/modules/input/input_dinput.cpp b/src/osd/modules/input/input_dinput.cpp index bea8b3b1ac7..6f581b0839a 100644 --- a/src/osd/modules/input/input_dinput.cpp +++ b/src/osd/modules/input/input_dinput.cpp @@ -9,7 +9,7 @@ #include "input_module.h" #include "modules/osdmodule.h" -#if defined(OSD_WINDOWS) && (_WIN32_WINNT >= 0x0602) +#if defined(OSD_WINDOWS) // standard windows headers #define WIN32_LEAN_AND_MEAN