8 #ifndef _PLATFORM_AGILE_H_
9 #define _PLATFORM_AGILE_H_
16 #include <wrl\client.h>
18 #if !defined(__cplusplus_winrt)
19 #error agile.h can only be used with /ZW
26 __declspec(dllimport) IUnknown* __stdcall GetObjectContext();
27 __declspec(dllimport) HRESULT __stdcall GetProxyImpl(::IUnknown*, REFIID, ::IUnknown*, ::IUnknown**);
28 __declspec(dllimport) HRESULT __stdcall ReleaseInContextImpl(::IUnknown*, ::IUnknown*);
33 return GetProxyImpl(*reinterpret_cast<IUnknown**>(&ObjectIn), __uuidof(T^) , ContextCallBack, reinterpret_cast< ::IUnknown**>(Proxy));
39 return ReleaseInContextImpl(ObjectIn, ContextCallBack);
48 AgileHelper(__abi_IUnknown* p,
bool release =
true) : _p(p), _release(release)
54 _other._release =
true;
59 _release = other._release;
61 _other._release =
true;
76 return reinterpret_cast<T^
>(
_p);
82 return reinterpret_cast<T^
>(
_p);
106 #pragma warning(push)
107 #pragma warning(disable: 4451) // Usage of ref class inside this context can lead to invalid marshaling of object across contexts
132 _contextCallback = Details::GetObjectContext();
141 if (
object !=
nullptr)
143 ::Microsoft::WRL::ComPtr< ::IAgileObject> checkIfAgile;
144 HRESULT hr =
reinterpret_cast< ::IUnknown*
>(object)->QueryInterface(__uuidof(::IAgileObject), &checkIfAgile);
160 Agile() throw() : _object(
nullptr), _contextToken(0), _agileState(
AgileState::Unknown)
164 Agile(nullptr_t) throw() : _object(
nullptr), _contextToken(0), _agileState(
AgileState::Unknown)
200 ULONG_PTR currentContextToken;
202 if (currentContextToken == _contextToken)
216 ::Microsoft::WRL::ComPtr< ::IAgileObject> checkIfAgile;
217 HRESULT hr =
reinterpret_cast<IUnknown*
>(localObject)->QueryInterface(__uuidof(::IAgileObject), &checkIfAgile);
220 auto pThis =
const_cast<Agile*
>(
this);
222 pThis->_contextToken = 0;
223 pThis->_contextCallback =
nullptr;
228 auto pThis =
const_cast<Agile*
>(
this);
262 Agile(
object).Swap(*
this);
276 std::swap(_contextCallback,
object._contextCallback);
277 std::swap(_contextToken,
object._contextToken);
278 std::swap(_agileState,
object._agileState);
287 IUnknown* pObject = *(::IUnknown**) (&_object);
289 *(IUnknown**) (&_object) =
nullptr;
291 ULONG_PTR currentContextToken;
293 if (_contextToken == 0 || _contextCallback ==
nullptr || _contextToken == currentContextToken)
301 _contextCallback =
nullptr;
309 return _object ==
nullptr;
314 return _object == other._object && _contextToken == other._contextToken;
319 if (reinterpret_cast<void*>(_object) < reinterpret_cast<void*>(other._object))
324 return _object == other._object && _contextToken < other._contextToken;
328 template <
typename T>
340 Agile(nullptr_t) throw() : _object(
nullptr)
391 if (_object !=
object)
417 return _object ==
nullptr;
422 return _object == other._object;
427 return reinterpret_cast<void*
>(
_object) < reinterpret_cast<void*>(other._object);
442 return !(a ==
nullptr);
448 return !(a ==
nullptr);
459 #endif // _PLATFORM_AGILE_H_
#define S_OK
Definition: comutil.h:62
void __abi_ThrowIfFailed(long __hrArg)
Definition: vccorlib.h:96
void swap(array< _Ty, _Size > &_Left, array< _Ty, _Size > &_Right) _NOEXCEPT_OP(_NOEXCEPT_OP(_Left.swap(_Right)))
Definition: array:433
#define false
Definition: stdbool.h:16