8 #ifndef _WRL_IMPLEMENTS_H_
9 #define _WRL_IMPLEMENTS_H_
15 #pragma region includes
17 #include <inspectable.h>
22 #include <activation.h>
23 #include <WinString.h>
31 #include <wrl\internal.h>
33 #include <wrl\client.h>
39 #ifdef WRL_RO_ERROR_API_ENABLED
40 # include "roerrorapi.h"
49 # pragma region disable warnings
51 # pragma warning(push)
52 # pragma warning(disable : 4584)
53 # pragma warning(disable : 4481)
57 # define WRT_NO_VTABLE __declspec(novtable)
59 # define WRT_NO_VTABLE
88 template <
unsigned int flags>
91 static const unsigned int value = flags;
113 template <
typename FactoryInterface = IInspectable>
119 template <
unsigned int RuntimeClassTypeT>
124 #ifdef WRL_RO_ERROR_API_ENABLED
125 ::RoOriginateError(hr, message);
127 UNREFERENCED_PARAMETER(hr);
128 UNREFERENCED_PARAMETER(message);
138 UNREFERENCED_PARAMETER(hr);
139 UNREFERENCED_PARAMETER(message);
153 # pragma section("minATL$__a", read)
155 # pragma section("minATL$__f", read)
157 # pragma section("minATL$__m", read)
159 # pragma section("minATL$__r", read)
160 # pragma section("minATL$__z", read)
187 static void* moduleLock_;
189 static_assert(
sizeof(moduleLock_) ==
sizeof(SRWLOCK),
"cacheLock must have the same size as SRWLOCK");
209 ::InterlockedCompareExchangePointer(
210 reinterpret_cast<void* volatile*
>(&module_),
this,
nullptr) ==
nullptr &&
211 "The module was already instantiated");
213 [[maybe_unused]] SRWLOCK initSRWLOCK = SRWLOCK_INIT;
215 reinterpret_cast<SRWLOCK*
>(&moduleLock_)->Ptr == initSRWLOCK.Ptr &&
216 "Different value for moduleLock_ than SRWLOCK_INIT");
229 ::InterlockedCompareExchangePointer(
230 reinterpret_cast<void* volatile*
>(&module_),
nullptr,
this) ==
this &&
231 "The module was already instantiated");
263 return reinterpret_cast<SRWLOCK*
>(&moduleLock_);
266 STDMETHOD(RegisterWinRTObject)
267 (_In_opt_z_
const wchar_t*,
271 STDMETHOD(UnregisterWinRTObject)(_In_opt_z_
const wchar_t*, RO_REGISTRATION_COOKIE) = 0;
272 STDMETHOD(RegisterCOMObject)
273 (_In_opt_z_
const wchar_t*, IID*, IClassFactory**, _Inout_ DWORD*,
unsigned int) = 0;
274 STDMETHOD(UnregisterCOMObject)(_In_opt_z_
const wchar_t*, _Inout_ DWORD*,
unsigned int) = 0;
279 __declspec(selectany)
void* ModuleBase::moduleLock_ =
nullptr;
282 #pragma region helper types
291 void*
operator new(size_t)
throw()
298 void*
operator new(size_t,
void* placement)
throw()
309 template <
unsigned int RuntimeClassTypeT>
313 template <
typename T>
314 static HRESULT
AsIID(T* implements, REFIID riid,
void** ppvObject)
throw()
316 *ppvObject =
nullptr;
318 # pragma warning(push)
320 # pragma warning(disable : 4127)
322 # pragma warning(disable : 6326)
325 bool isRefDelegated =
false;
328 if (InlineIsEqualGUID(riid, __uuidof(IUnknown)) ||
329 ((RuntimeClassTypeT &
WinRt) != 0 && InlineIsEqualGUID(riid, __uuidof(IInspectable))))
331 # pragma warning(pop)
334 *ppvObject = implements->CastToUnknown();
335 static_cast<IUnknown*
>(*ppvObject)->AddRef();
339 HRESULT hr = implements->CanCastTo(riid, ppvObject, &isRefDelegated);
340 if (SUCCEEDED(hr) && !isRefDelegated)
342 static_cast<IUnknown*
>(*ppvObject)->AddRef();
346 # pragma warning(suppress : 6102)
348 _Analysis_assume_(SUCCEEDED(hr) || (*ppvObject ==
nullptr));
352 template <
typename T>
356 _When_(*iidCount == 0, _At_(*iids, _Post_null_)) _When_(*iidCount > 0, _At_(*iids, _Post_notnull_))
357 _Result_nullonfailure_ IID** iids)
throw()
361 unsigned long count = implements->GetIidCount();
369 IID* iidArray =
reinterpret_cast<IID*
>(::CoTaskMemAlloc(
sizeof(IID) * count));
370 if (iidArray ==
nullptr)
372 return E_OUTOFMEMORY;
375 unsigned long index = 0;
378 implements->FillArrayWithIid(&index, iidArray);
402 bool doStrictCheck =
true,
407 template <
typename I,
bool doStrictCheck>
412 #ifdef __WRL_STRICT__
416 __is_base_of(IUnknown, I) && !__is_base_of(IInspectable, I) &&
418 "'I' has to derive from 'IUnknown' and not from 'IInspectable'. 'I' must not be IUnknown.");
420 static_assert(__is_base_of(IUnknown, I),
"'I' has to derive from 'IUnknown'.");
426 template <
typename I,
bool doStrictCheck>
431 #ifdef __WRL_STRICT__
435 __is_base_of(IUnknown, I) &&
437 : __is_base_of(IInspectable, I)),
438 "'I' has to derive from 'IUnknown' and must not be IUnknown and/or IInspectable.");
440 static_assert(__is_base_of(IUnknown, I),
"'I' has to derive from 'IUnknown'.");
446 template <
typename I,
bool doStrictCheck>
451 #ifdef __WRL_STRICT__
458 "'I' has to derive from 'IWeakReferenceSource' or 'IInspectable' and must not be IInspectable");
463 __is_base_of(IInspectable, I),
464 "'I' has to derive from 'IWeakReference', 'IWeakReferenceSource' or 'IInspectable'");
470 template <
unsigned int type,
typename I>
475 #ifdef __WRL_STRICT__
481 "Implements class must have the same and/or compatibile flags configuration");
487 template <
unsigned int type,
typename I>
492 #ifdef __WRL_STRICT__
496 "Implements class must have the same and/or compatible flags configuration."
497 "If you use WRL::FtmBase it cannot be specified as first template parameter on RuntimeClass");
506 template <
typename I0>
510 static const unsigned long IidCount = 1;
512 template <
unsigned int ClassType>
518 template <
typename T>
521 return static_cast<Base*
>(ptr);
524 template <
typename T>
527 return static_cast<IUnknown*
>(
static_cast<Base*
>(ptr));
530 template <
typename T>
531 _Success_(
return ==
true) static
bool CanCastTo(T* ptr, REFIID riid, _Outptr_
void** ppv) throw()
535 if (InlineIsEqualGUID(riid, __uuidof(
Base)))
537 *ppv =
static_cast<Base*
>(ptr);
546 *(iids + *index) = __uuidof(
Base);
552 template <
typename CloakedType>
556 static const unsigned long IidCount = 0;
558 template <
unsigned int ClassType>
564 template <
typename T>
567 return static_cast<Base*
>(ptr);
570 template <
typename T>
573 return static_cast<IUnknown*
>(
static_cast<Base*
>(ptr));
576 template <
typename T>
577 _Success_(
return ==
true) static
bool CanCastTo(T* ptr, REFIID riid, _Outptr_
void** ppv) throw()
581 if (InlineIsEqualGUID(riid, __uuidof(
Base)))
583 *ppv =
static_cast<Base*
>(ptr);
600 static const unsigned long IidCount = 0;
602 template <
unsigned int ClassType>
609 template <
typename T>
610 _Success_(
return ==
true) static
bool CanCastTo(T*, REFIID, _Outptr_
void**) throw()
617 template <
typename I,
typename Base>
626 "'I' needs to inherit from 'Base'.");
630 template <
typename I>
653 typename I2 = Details::Nil,
654 typename I3 = Details::Nil,
655 typename I4 = Details::Nil,
656 typename I5 = Details::Nil,
657 typename I6 = Details::Nil,
658 typename I7 = Details::Nil,
659 typename I8 = Details::Nil,
660 typename I9 = Details::Nil>
664 template <
unsigned int ClassType>
689 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv)
throw()
735 typename DerivedType,
747 struct ChainInterfaces<
MixIn<DerivedType, BaseType, hasImplements>, I1, I2, I3, I4, I5, I6, I7, I8, I9>
751 "Cannot use ChainInterfaces<MixIn<...>> to Mix a class implementing interfaces using \"Implements\"");
754 template <
unsigned int ClassType>
779 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv)
throw()
781 BaseType* ptr =
static_cast<BaseType*
>(
static_cast<DerivedType*
>(
this));
805 Details::InterfaceTraits<I2>::
IidCount + Details::InterfaceTraits<I3>::
IidCount +
806 Details::InterfaceTraits<I4>::
IidCount + Details::InterfaceTraits<I5>::
IidCount +
807 Details::InterfaceTraits<I6>::
IidCount + Details::InterfaceTraits<I7>::
IidCount +
808 Details::InterfaceTraits<I8>::
IidCount + Details::InterfaceTraits<I9>::
IidCount;
827 #pragma region Implements helper templates
832 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename... TInterfaces>
835 template <
typename T>
839 template <
typename I0,
bool isImplements>
842 template <
typename I0>
848 template <
typename I0>
854 template <
typename I0>
862 template <
typename DerivedType,
typename BaseType,
bool hasImplements>
870 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename... Bases>
873 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename I0,
typename... Bases>
885 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename... Bases>
891 template <
typename RuntimeClassFlagsT,
bool doStrictCheck>
898 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename I0,
typename... TInterfaces>
903 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TOtherInterfaces>
905 template <
unsigned int RuntimeClassTypeT>
909 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
914 if (InlineIsEqualGUID(riid, __uuidof(I0)))
916 *ppv =
reinterpret_cast<I0*
>(
reinterpret_cast<void*
>(
this));
919 return AdjustImplements<RuntimeClassFlagsT, true, TInterfaces...>::Type::CanCastTo(
920 riid, ppv, pRefDelegated);
927 return reinterpret_cast<I0*
>(
reinterpret_cast<void*
>(
this));
932 return 1 + AdjustImplements<RuntimeClassFlagsT, true, TInterfaces...>::Type::GetIidCount();
938 *(iids + *index) = __uuidof(I0);
940 AdjustImplements<RuntimeClassFlagsT, true, TInterfaces...>::Type::FillArrayWithIid(index, iids);
946 template <
typename base,
typename disciminator>
951 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename I0,
typename... TInterfaces>
956 ImplementsHelper<RuntimeClassFlagsT, doStrictCheck, ImplementsMarker<I0>, TInterfaces...>>
958 typename AdjustImplements<RuntimeClassFlagsT, true, TInterfaces...>::Type,
959 ImplementsHelper<RuntimeClassFlagsT, doStrictCheck, ImplementsMarker<I0>, TInterfaces...>>
961 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TOtherInterfaces>
963 template <
unsigned int RuntimeClassTypeT>
969 ImplementsHelper<RuntimeClassFlagsT, doStrictCheck, ImplementsMarker<I0>, TInterfaces...>>
973 ImplementsHelper<RuntimeClassFlagsT, doStrictCheck, ImplementsMarker<I0>, TInterfaces...>>
980 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
983 HRESULT hr = CurrentType::CanCastTo(riid, ppv);
984 if (hr == E_NOINTERFACE)
986 hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
994 return CurrentType::CastToUnknown();
999 return CurrentType::GetIidCount() + BaseType::GetIidCount();
1005 CurrentType::FillArrayWithIid(index, iids);
1006 BaseType::FillArrayWithIid(index, iids);
1015 typename RuntimeClassFlagsT,
1019 typename... TInterfaces>
1024 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TOtherInterfaces>
1026 template <
unsigned int RuntimeClassTypeT>
1030 typedef typename AdjustImplements<RuntimeClassFlagsT, doStrictCheck, I0>::Type
CurrentType;
1033 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
1037 HRESULT hr = CurrentType::CanCastTo(riid, ppv, pRefDelegated);
1042 return BaseType::CanCastTo(riid, ppv, pRefDelegated);
1047 return CurrentType::CastToUnknown();
1053 return BaseType::GetIidCount();
1058 BaseType::FillArrayWithIid(index, iids);
1062 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename I0>
1066 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TInterfaces>
1068 template <
unsigned int RuntimeClassTypeT>
1072 typedef typename AdjustImplements<RuntimeClassFlagsT, doStrictCheck, I0>::Type
CurrentType;
1074 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
1078 return CurrentType::CanCastTo(riid, ppv, pRefDelegated);
1083 return CurrentType::CastToUnknown();
1099 template <
typename RuntimeClassFlagsT,
bool doStrictCheck>
1102 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TInterfaces>
1104 template <
unsigned int RuntimeClassTypeT>
1108 template <
unsigned int RuntimeClassTypeT>
1112 CanCastTo(REFIID , _Outptr_
void** ,
bool* =
nullptr) throw()
1114 return E_NOINTERFACE;
1130 typename RuntimeClassFlagsT,
1142 typename... TInterfaces>
1146 ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>,
1151 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TOtherInterfaces>
1153 template <
unsigned int RuntimeClassTypeT>
1157 template <
unsigned int RuntimeClassTypeT>
1161 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
1164 RuntimeClassFlagsT::value>();
1166 HRESULT hr =
ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>::CanCastTo(riid, ppv);
1169 hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
1187 ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>::FillArrayWithIid(index, iids);
1188 BaseType::FillArrayWithIid(index, iids);
1194 typename RuntimeClassFlagsT,
1195 typename DerivedType,
1196 typename BaseMixInType,
1198 typename... TInterfaces,
1203 MixIn<DerivedType, BaseMixInType, hasImplements>,
1204 TInterfaces...> :
AdjustImplements<RuntimeClassFlagsT, true, TInterfaces...>::Type
1206 static_assert(hasImplements,
"Cannot use MixIn to with a class not deriving from \"Implements\"");
1208 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TOtherInterfaces>
1210 template <
unsigned int RuntimeClassTypeT>
1214 template <
unsigned int RuntimeClassTypeT>
1218 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
1223 doStrictCheck>::Verify();
1225 HRESULT hr =
static_cast<BaseMixInType*
>(
static_cast<DerivedType*
>(
this))->CanCastTo(riid, ppv);
1228 hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
1236 return static_cast<BaseMixInType*
>(
static_cast<DerivedType*
>(
this))->CastToUnknown();
1241 return static_cast<BaseMixInType*
>(
static_cast<DerivedType*
>(
this))->GetIidCount() +
1242 BaseType::GetIidCount();
1247 static_cast<BaseMixInType*
>(
static_cast<DerivedType*
>(
this))->FillArrayWithIid(index, iids);
1248 BaseType::FillArrayWithIid(index, iids);
1254 template <
typename I0,
typename...>
1257 static const bool value =
false;
1260 template <
typename... TInterfaces>
1273 typename RuntimeClassFlagsT,
1274 typename FactoryInterface,
1276 typename... TInterfaces>
1279 :
ImplementsHelper<RuntimeClassFlagsT, true, ComposableBase<FactoryInterface>>
1281 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TOtherInterfaces>
1283 template <
unsigned int RuntimeClassTypeT>
1287 template <
unsigned int RuntimeClassTypeT>
1290 typedef ImplementsHelper<RuntimeClassFlagsT, true, ComposableBase<FactoryInterface>>
BaseType;
1292 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated =
nullptr) throw()
1296 "ComposableBase should be the last template parameter to RuntimeClass");
1297 return BaseType::CanCastTo(riid, ppv, pRefDelegated);
1304 "ComposableBase should be the last template parameter to RuntimeClass");
1305 return BaseType::CastToUnknown();
1312 "ComposableBase should be the last template parameter to RuntimeClass");
1313 return BaseType::GetIidCount();
1320 "ComposableBase should be the last template parameter to RuntimeClass");
1321 BaseType::FillArrayWithIid(index, iids);
1325 template <
typename RuntimeClassFlagsT,
typename FactoryInterface,
bool doStrictCheck>
1328 template <
typename OtherRuntimeClassFlagsT,
bool OtherDoStrictCheck,
typename... TInterfaces>
1330 template <
unsigned int RuntimeClassTypeT>
1334 template <
unsigned int RuntimeClassTypeT>
1337 HRESULT
CanCastTo(REFIID riid, _Outptr_
void** ppv,
bool* pRefDelegated)
throw()
1339 *pRefDelegated =
true;
1340 return composableBase_.CopyTo(riid, ppv);
1355 for (
unsigned long i = 0; i < iidCount_; i++)
1357 *(iids + *index) = *(iidsCached_ + i);
1363 : iidsCached_(
nullptr)
1369 ::CoTaskMemFree(iidsCached_);
1370 iidsCached_ =
nullptr;
1378 if (composableBase_ !=
nullptr)
1380 #ifdef WRL_RO_ERROR_API_ENABLED
1382 E_UNEXPECTED,
nullptr);
1384 return E_UNEXPECTED;
1387 HRESULT hr = base->GetIids(&iidCount_, &iidsCached_);
1390 composableBase_ = base;
1391 composableBaseFactory_ = baseFactory;
1398 return composableBase_;
1403 return composableBaseFactory_;
1410 unsigned long iidCount_;
1422 template <
typename I0,
typename... TInterfaces>
1437 typename Details::AdjustImplements<RuntimeClassFlags<WinRt>,
true, I0, TInterfaces...>::Type
BaseType;
1438 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename... TOtherInterfaces>
1440 template <
unsigned int RuntimeClassTypeT>
1445 return BaseType::CanCastTo(riid, ppv);
1450 return BaseType::CastToUnknown();
1455 return BaseType::GetIidCount();
1460 BaseType::FillArrayWithIid(index, iids);
1464 template <
int flags,
typename I0,
typename... TInterfaces>
1475 typename Details::AdjustImplements<RuntimeClassFlags<flags>,
true, I0, TInterfaces...>::Type
BaseType;
1476 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename... TOtherInterfaces>
1478 template <
unsigned int RuntimeClassTypeT>
1483 return BaseType::CanCastTo(riid, ppv);
1488 return BaseType::CastToUnknown();
1493 return BaseType::GetIidCount();
1498 BaseType::FillArrayWithIid(index, iids);
1504 ::Microsoft::WRL::RuntimeClassFlags<WinRtClassicComMix>,
1505 ::Microsoft::WRL::CloakedIid<::IMarshal>>
1517 template <
typename RuntimeClassFlagsT,
bool doStrictCheck,
typename... TInterfaces>
1524 if (InlineIsEqualGUID(
riid, __uuidof(::IAgileObject)))
1538 if (SUCCEEDED(::CoCreateFreeThreadedMarshaler(
nullptr, &unknown)))
1550 # pragma warning(suppress : 6101)
1552 STDMETHOD(GetUnmarshalClass)
1558 CLSID* pCid)
override
1564 return E_OUTOFMEMORY;
1568 # pragma warning(suppress : 6101)
1570 STDMETHOD(GetMarshalSizeMax)
1576 DWORD* pSize)
override
1582 return E_OUTOFMEMORY;
1585 STDMETHOD(MarshalInterface)
1597 return E_OUTOFMEMORY;
1601 # pragma warning(suppress : 6101)
1609 return E_OUTOFMEMORY;
1618 return E_OUTOFMEMORY;
1627 return E_OUTOFMEMORY;
1633 return ::CoCreateInstance(
1634 CLSID_StdGlobalInterfaceTable,
1636 CLSCTX_INPROC_SERVER,
1637 __uuidof(IGlobalInterfaceTable),
1638 reinterpret_cast<void**
>(git));
1647 #ifdef _PERF_COUNTERS
1651 ULONG GetAddRefCount()
throw()
1653 return addRefCount_;
1656 ULONG GetReleaseCount()
throw()
1658 return releaseCount_;
1661 ULONG GetQueryInterfaceCount()
throw()
1663 return queryInterfaceCount_;
1666 void ResetPerfCounters()
throw()
1670 queryInterfaceCount_ = 0;
1674 PerfCountersBase()
throw()
1677 , queryInterfaceCount_(0)
1680 void IncrementAddRefCount()
throw()
1682 InterlockedIncrement(&addRefCount_);
1685 void IncrementReleaseCount()
throw()
1687 InterlockedIncrement(&releaseCount_);
1690 void IncrementQueryInterfaceCount()
throw()
1692 InterlockedIncrement(&queryInterfaceCount_);
1696 volatile unsigned long addRefCount_;
1697 volatile unsigned long releaseCount_;
1698 volatile unsigned long queryInterfaceCount_;
1702 #if defined(_X86_) || defined(_AMD64_)
1704 # define UnknownIncrementReference InterlockedIncrement
1705 # define UnknownDecrementReference InterlockedDecrement
1706 # define UnknownBarrierAfterInterlock()
1707 # define UnknownInterlockedCompareExchangePointer InterlockedCompareExchangePointer
1708 # define UnknownInterlockedCompareExchangePointerForIncrement InterlockedCompareExchangePointer
1709 # define UnknownInterlockedCompareExchangePointerForRelease InterlockedCompareExchangePointer
1710 # define UnknownInterlockedCompareExchangeForIncrement InterlockedCompareExchange
1711 # define UnknownInterlockedCompareExchangeForRelease InterlockedCompareExchange
1713 #elif defined(_ARM_)
1715 # define UnknownIncrementReference InterlockedIncrementNoFence
1716 # define UnknownDecrementReference InterlockedDecrementRelease
1717 # define UnknownBarrierAfterInterlock() __dmb(_ARM_BARRIER_ISH)
1718 # define UnknownInterlockedCompareExchangePointer InterlockedCompareExchangePointer
1719 # define UnknownInterlockedCompareExchangePointerForIncrement InterlockedCompareExchangePointerNoFence
1720 # define UnknownInterlockedCompareExchangePointerForRelease InterlockedCompareExchangePointerRelease
1721 # define UnknownInterlockedCompareExchangeForIncrement InterlockedCompareExchangeNoFence
1722 # define UnknownInterlockedCompareExchangeForRelease InterlockedCompareExchangeRelease
1724 #elif defined(_ARM64_)
1726 # define UnknownIncrementReference InterlockedIncrementNoFence
1727 # define UnknownDecrementReference InterlockedDecrementRelease
1728 # define UnknownBarrierAfterInterlock() __dmb(_ARM64_BARRIER_ISH)
1729 # define UnknownInterlockedCompareExchangePointer InterlockedCompareExchangePointer
1730 # define UnknownInterlockedCompareExchangePointerForIncrement InterlockedCompareExchangePointerNoFence
1731 # define UnknownInterlockedCompareExchangePointerForRelease InterlockedCompareExchangePointerRelease
1732 # define UnknownInterlockedCompareExchangeForIncrement InterlockedCompareExchangeNoFence
1733 # define UnknownInterlockedCompareExchangeForRelease InterlockedCompareExchangeRelease
1737 # error Unsupported architecture.
1743 #define DETAILS_RTCLASS_FLAGS_ARGUMENTS(RuntimeClassFlagsT) \
1744 RuntimeClassFlagsT, (RuntimeClassFlagsT::value & InhibitWeakReference) == 0, \
1745 (RuntimeClassFlagsT::value & WinRt) == WinRt, __WRL_IMPLEMENTS_FTM_BASE__(RuntimeClassFlagsT::value)
1748 class RuntimeClassFlagsT,
1749 bool implementsWeakReferenceSource,
1750 bool implementsInspectable,
1751 bool implementsFtmBase,
1752 typename... TInterfaces>
1756 # pragma warning(push)
1758 # pragma warning(disable : 6388)
1765 long oldValue = refcount;
1766 while (oldValue != LONG_MAX &&
1767 (UnknownInterlockedCompareExchangeForIncrement(&refcount, oldValue + 1, oldValue) != oldValue))
1769 oldValue = refcount;
1772 if (oldValue != LONG_MAX)
1774 return static_cast<unsigned long>(oldValue + 1);
1778 return static_cast<unsigned long>(LONG_MAX);
1784 long oldValue = refcount;
1785 while (oldValue != LONG_MAX &&
1786 (UnknownInterlockedCompareExchangeForRelease(&refcount, oldValue - 1, oldValue) != oldValue))
1788 oldValue = refcount;
1791 return static_cast<unsigned long>(oldValue - 1);
1795 class RuntimeClassFlagsT,
1796 bool implementsWeakReferenceSource,
1797 bool implementsFtmBase,
1798 typename... TInterfaces>
1801 implementsWeakReferenceSource,
1809 #ifdef _PERF_COUNTERS
1810 ,
public PerfCountersBase
1816 STDMETHOD(QueryInterface)(REFIID riid,
void** ppvObject)
1818 #ifdef _PERF_COUNTERS
1819 IncrementQueryInterfaceCount();
1821 return Super::AsIID(
this, riid, ppvObject);
1826 return InternalAddRef();
1831 ULONG ref = InternalRelease();
1837 if (modulePtr !=
nullptr)
1839 modulePtr->DecrementObjectCount();
1857 refcount_ = -(LONG_MAX / 2);
1862 #ifdef _PERF_COUNTERS
1863 IncrementAddRefCount();
1870 #ifdef _PERF_COUNTERS
1871 IncrementReleaseCount();
1880 UnknownBarrierAfterInterlock();
1893 volatile long refcount_;
1896 template <
typename I,
bool isImplementsBased = __is_base_of(ImplementsBase, I)>
1899 template <
typename I>
1902 static const bool isIInspectable = __is_base_of(IInspectable, I);
1905 template <
typename I>
1911 #ifdef __WRL_STRICT__
1912 template <
typename I0,
bool isIInspectable = true>
1914 template <typename I0, bool isIInspectable = HasIInspectable<I0>::isIInspectable>
1918 template <
typename I0>
1924 template <
typename I0>
1931 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
1936 typename IInspectableInjector<I0>::InspectableIfNeeded,
1938 TInterfaces...>::Type
1942 #ifdef _PERF_COUNTERS
1943 ,
public PerfCountersBase
1949 STDMETHOD(QueryInterface)(REFIID riid,
void** ppvObject)
1951 #ifdef _PERF_COUNTERS
1952 IncrementQueryInterfaceCount();
1954 return Super::AsIID(
this, riid, ppvObject);
1959 return InternalAddRef();
1964 ULONG ref = InternalRelease();
1970 if (modulePtr !=
nullptr)
1972 modulePtr->DecrementObjectCount();
1982 _When_(*iidCount == 0, _At_(*iids, _Post_null_)) _When_(*iidCount > 0, _At_(*iids, _Post_notnull_))
1983 _Result_nullonfailure_ IID** iids)
1985 return Super::GetImplementedIIDS(
this, iidCount, iids);
1988 #if !defined(__WRL_STRICT__) || !defined(__WRL_FORCE_INSPECTABLE_CLASS_MACRO__)
1989 STDMETHOD(GetRuntimeClassName)(HSTRING* runtimeClassName)
1991 *runtimeClassName =
nullptr;
1993 __WRL_ASSERT__(
false &&
"Use InspectableClass macro to set runtime class name and trust level.");
1995 # ifdef WRL_RO_ERROR_API_ENABLED
1997 E_NOTIMPL,
nullptr);
2002 STDMETHOD(GetTrustLevel)(::TrustLevel*)
2004 __WRL_ASSERT__(
false &&
"Use InspectableClass macro to set runtime class name and trust level.");
2006 # ifdef WRL_RO_ERROR_API_ENABLED
2008 E_NOTIMPL,
nullptr);
2025 refcount_ = -(LONG_MAX / 2);
2030 #ifdef _PERF_COUNTERS
2031 IncrementAddRefCount();
2038 #ifdef _PERF_COUNTERS
2039 IncrementReleaseCount();
2048 UnknownBarrierAfterInterlock();
2059 volatile long refcount_;
2090 UnknownBarrierAfterInterlock();
2143 class WeakReferenceImpl;
2153 LONG ReadULongPtrNoFence(DWORD
const volatile* Source)
2158 Value = __iso_volatile_load32((
int*)Source);
2162 #elif defined(_ARM64_)
2166 ReadULongPtrNoFence(DWORD64
const volatile* Source)
2171 Value = __iso_volatile_load64((__int64*)Source);
2175 #elif defined(_X86_)
2178 LONG ReadULongPtrNoFence(DWORD
const volatile* Source)
2187 #elif defined(_AMD64_)
2191 ReadULongPtrNoFence(DWORD64
const volatile* Source)
2196 Value =
static_cast<LONG64
>(*Source);
2202 # error Unsupported architecture.
2206 template <
typename T>
2209 ULONG_PTR currentValue = ReadULongPtrNoFence(
reinterpret_cast<const volatile ULONG_PTR*
>(value));
2210 const T* currentPointerToValue =
reinterpret_cast<T*
>(¤tValue);
2211 return *currentPointerToValue;
2218 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2223 typename IInspectableInjector<I0>::InspectableIfNeeded,
2225 IWeakReferenceSource,
2226 TInterfaces...>::Type
2229 #ifdef _PERF_COUNTERS
2230 ,
public PerfCountersBase
2238 refCount_.rawValue = 1;
2241 STDMETHOD(QueryInterface)(REFIID riid,
void** ppvObject)
2243 #ifdef _PERF_COUNTERS
2244 IncrementQueryInterfaceCount();
2246 return Super::AsIID(
this, riid, ppvObject);
2251 return InternalAddRef();
2256 ULONG ref = InternalRelease();
2262 if (modulePtr !=
nullptr)
2264 modulePtr->DecrementObjectCount();
2274 _When_(*iidCount == 0, _At_(*iids, _Post_null_)) _When_(*iidCount > 0, _At_(*iids, _Post_notnull_))
2275 _Result_nullonfailure_ IID** iids)
2277 return Super::GetImplementedIIDS(
this, iidCount, iids);
2280 #if !defined(__WRL_STRICT__) || !defined(__WRL_FORCE_INSPECTABLE_CLASS_MACRO__)
2281 STDMETHOD(GetRuntimeClassName)(HSTRING* runtimeClassName)
2283 *runtimeClassName =
nullptr;
2285 __WRL_ASSERT__(
false &&
"Use InspectableClass macro to set runtime class name and trust level.");
2287 # ifdef WRL_RO_ERROR_API_ENABLED
2289 E_NOTIMPL,
nullptr);
2294 STDMETHOD(GetTrustLevel)(::TrustLevel*)
2296 __WRL_ASSERT__(
false &&
"Use InspectableClass macro to set runtime class name and trust level.");
2297 # ifdef WRL_RO_ERROR_API_ENABLED
2299 E_NOTIMPL,
nullptr);
2305 STDMETHOD(GetWeakReference)(_Outptr_
IWeakReference** weakReference);
2310 template <
unsigned int RuntimeClassTypeT>
2318 TInterfaces...>::Type;
2321 unsigned long InternalAddRef() throw();
2323 unsigned long InternalRelease() throw();
2325 unsigned long GetRefCount() const throw();
2329 #ifdef __WRL_UNITTEST__
2341 return static_cast<INT_PTR
>(
2342 (
reinterpret_cast<INT_PTR
>(value) >>
static_cast<INT_PTR
>(1)) |
2352 # pragma warning(pop)
2355 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2357 :
public RuntimeClassImpl<RuntimeClassFlagsT, false, true, false, I0, TInterfaces...>
2360 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2362 :
public RuntimeClassImpl<RuntimeClassFlagsT, true, true, false, I0, FtmBase, TInterfaces...>
2367 template <
typename... TInterfaces>
2375 class RuntimeClassFlagsT,
2377 bool implementsInspectable = (RuntimeClassFlagsT::value &
WinRt) ==
WinRt,
2382 typename RuntimeClassFlagsT,
2383 bool implementsWeakReferenceSource,
2384 bool implementsInspectable,
2385 bool implementsFtmBase,
2386 typename... TInterfaces>
2390 implementsWeakReferenceSource,
2391 implementsInspectable,
2395 implementsWeakReferenceSource,
2396 implementsInspectable,
2402 # pragma warning(suppress : 6101)
2418 template <
typename... TInterfaces>
2421 RuntimeClassImpl<DETAILS_RTCLASS_FLAGS_ARGUMENTS(RuntimeClassFlags<WinRt>), TInterfaces...>
2428 # pragma warning(suppress : 6101)
2442 if (modulePtr !=
nullptr)
2444 modulePtr->IncrementObjectCount();
2450 template <
unsigned int classFlags,
typename... TInterfaces>
2453 RuntimeClassImpl<DETAILS_RTCLASS_FLAGS_ARGUMENTS(RuntimeClassFlags<classFlags>), TInterfaces...>
2460 # pragma warning(suppress : 6101)
2474 if (modulePtr !=
nullptr)
2476 modulePtr->IncrementObjectCount();
2504 (REFIID
riid, _Outptr_result_maybenull_ _Result_nullonfailure_ IInspectable**
ppvObject)
2518 if (::_InterlockedCompareExchange(&this->
strongRefCount_, ref + 1, ref) == ref)
2520 #ifdef _PERF_COUNTERS
2531 unknown_->Release();
2539 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2550 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2555 ReadValueFromPointerNoFence<ReferenceCountOrWeakReferencePointer>(&refCount_);
2564 return static_cast<unsigned long>(currentValue.
refCount);
2568 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2572 #ifdef _PERF_COUNTERS
2573 IncrementAddRefCount();
2577 ReadValueFromPointerNoFence<ReferenceCountOrWeakReferencePointer>(&refCount_);
2583 if (
static_cast<long>(currentValue.
refCount) == LONG_MAX)
2588 UINT_PTR updateValue = currentValue.
refCount + 1;
2590 #ifdef __WRL_UNITTEST__
2591 OnBeforeInternalAddRefIncrement();
2594 INT_PTR previousValue =
2595 reinterpret_cast<INT_PTR
>(UnknownInterlockedCompareExchangePointerForIncrement(
2596 reinterpret_cast<PVOID*
>(&(refCount_.refCount)),
2597 reinterpret_cast<PVOID
>(updateValue),
2598 reinterpret_cast<PVOID
>(currentValue.
refCount)));
2599 if (previousValue == currentValue.
rawValue)
2601 return static_cast<unsigned long>(updateValue);
2604 currentValue.
rawValue = previousValue;
2614 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2618 #ifdef _PERF_COUNTERS
2619 IncrementReleaseCount();
2623 ReadValueFromPointerNoFence<ReferenceCountOrWeakReferencePointer>(&refCount_);
2629 if (
static_cast<long>(currentValue.
refCount) == LONG_MAX)
2631 return LONG_MAX - 1;
2634 UINT_PTR updateValue = currentValue.
refCount - 1;
2636 #ifdef __WRL_UNITTEST__
2637 OnBeforeInternalReleaseDecrement();
2640 INT_PTR previousValue =
2641 reinterpret_cast<INT_PTR
>(UnknownInterlockedCompareExchangePointerForIncrement(
2642 reinterpret_cast<PVOID*
>(&(refCount_.refCount)),
2643 reinterpret_cast<PVOID
>(updateValue),
2644 reinterpret_cast<PVOID
>(currentValue.
refCount)));
2645 if (previousValue == currentValue.
rawValue)
2647 return static_cast<unsigned long>(updateValue);
2650 currentValue.
rawValue = previousValue;
2660 template <
class RuntimeClassFlagsT,
typename I0,
typename... TInterfaces>
2661 COM_DECLSPEC_NOTHROW HRESULT
2666 INT_PTR encodedWeakRef = 0;
2668 ReadValueFromPointerNoFence<ReferenceCountOrWeakReferencePointer>(&refCount_);
2670 *weakReference =
nullptr;
2677 *weakReference = weakRef;
2683 if (weakRef ==
nullptr)
2685 return E_OUTOFMEMORY;
2692 INT_PTR previousValue = 0;
2696 #ifdef __WRL_UNITTEST__
2697 OnBeforeGetWeakReferenceSwap();
2700 previousValue =
reinterpret_cast<INT_PTR
>(UnknownInterlockedCompareExchangePointer(
2701 reinterpret_cast<PVOID*
>(
2702 &(this->refCount_.ifHighBitIsSetThenShiftLeftToYieldPointerToWeakReference)),
2703 reinterpret_cast<PVOID
>(encodedWeakRef),
2705 if (previousValue == currentValue.
rawValue)
2709 *weakReference = weakRef;
2720 *weakReference = weakRef;
2726 currentValue.
rawValue = previousValue;
2732 template <
typename T>
2742 if (buffer_ !=
nullptr)
2754 #ifdef __cpp_aligned_new
2755 if constexpr (
alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
2757 return buffer_ =
reinterpret_cast<char*
>(
operator new(
2758 sizeof(T),
static_cast<std::align_val_t
>(
alignof(T)), ::std::nothrow));
2761 return buffer_ =
reinterpret_cast<char*
>(
operator new(
sizeof(T), ::std::nothrow));
2776 # pragma region make overloads
2784 template <
typename T,
typename... TArgs>
2789 "Make can only instantiate types that derive from RuntimeClass");
2792 void* buffer = allocator.
Allocate();
2793 if (buffer !=
nullptr)
2795 auto ptr =
new (buffer) T(Details::Forward<TArgs>(args)...);
2803 # pragma warning(push)
2804 # pragma warning(disable : 6387 6388 28196)
2807 template <
typename T,
typename I,
typename... TArgs>
2812 "Make can only instantiate types that derive from RuntimeClass");
2813 static_assert(__is_base_of(I, T),
"The 'T' runtime class doesn't implement 'I' interface");
2816 void* buffer = allocator.
Allocate();
2817 if (buffer ==
nullptr)
2819 return E_OUTOFMEMORY;
2821 auto ptr =
new (buffer) T;
2825 HRESULT hr =
object->RuntimeClassInitialize(Details::Forward<TArgs>(args)...);
2830 return object.CopyTo(result);
2834 # pragma warning(pop)
2837 template <
typename T,
typename I,
typename... TArgs>
2840 return MakeAndInitialize<T>(ppvObject.ReleaseAndGetAddressOf(), Details::Forward<TArgs>(args)...);
2856 return Make<WeakReferenceImpl>(unk).Detach();
2860 #define InspectableClass(runtimeClassName, trustLevel) \
2863 static _Null_terminated_ const wchar_t* STDMETHODCALLTYPE InternalGetRuntimeClassName() throw() \
2866 (RuntimeClassT::ClassFlags::value & ::Microsoft::WRL::WinRtClassicComMix) == ::Microsoft::WRL::WinRt || \
2867 (RuntimeClassT::ClassFlags::value & ::Microsoft::WRL::WinRtClassicComMix) == \
2868 ::Microsoft::WRL::WinRtClassicComMix, \
2869 "'InspectableClass' macro must not be used with ClassicCom clasess."); \
2871 __is_base_of(::Microsoft::WRL::Details::RuntimeClassBase, RuntimeClassT), \
2872 "'InspectableClass' macro can only be used with ::Windows::WRL::RuntimeClass types"); \
2874 !__is_base_of(IActivationFactory, RuntimeClassT), \
2875 "Incorrect usage of IActivationFactory interface. Make sure that your RuntimeClass doesn't implement " \
2876 "IActivationFactory interface use ::Windows::WRL::ActivationFactory instead or 'InspectableClass' macro " \
2877 "is not used on ::Windows::WRL::ActivationFactory"); \
2878 return runtimeClassName; \
2880 static ::TrustLevel STDMETHODCALLTYPE InternalGetTrustLevel() throw() \
2882 return trustLevel; \
2884 STDMETHOD(GetRuntimeClassName)(HSTRING * runtimeName) override \
2886 *runtimeName = nullptr; \
2887 HRESULT hr = S_OK; \
2888 auto name = InternalGetRuntimeClassName(); \
2889 if (name != nullptr) \
2891 hr = ::WindowsCreateString(name, static_cast<UINT32>(::wcslen(name)), runtimeName); \
2895 STDMETHOD(GetTrustLevel)(::TrustLevel * trustLvl) override \
2897 *trustLvl = trustLevel; \
2900 STDMETHOD(GetIids) \
2901 (ULONG * iidCount, \
2902 _When_(*iidCount == 0, _At_(*iids, _Post_null_)) _When_(*iidCount > 0, _At_(*iids, _Post_notnull_)) \
2903 _Result_nullonfailure_ IID * \
2906 return RuntimeClassT::GetIids(iidCount, iids); \
2908 STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) override \
2910 bool handled = false; \
2911 HRESULT hr = this->CustomQueryInterface(riid, ppvObject, &handled); \
2912 if (FAILED(hr) || handled) \
2914 return RuntimeClassT::QueryInterface(riid, ppvObject); \
2916 STDMETHOD_(ULONG, Release)() override \
2918 return RuntimeClassT::Release(); \
2920 STDMETHOD_(ULONG, AddRef)() override \
2922 return RuntimeClassT::AddRef(); \
2927 #define MixInHelper() \
2930 STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject) \
2933 (RuntimeClassT::ClassFlags::value & ::Microsoft::WRL::WinRt) == 0, \
2934 "'MixInClass' macro must not be used with WinRt clasess."); \
2936 __is_base_of(::Microsoft::WRL::Details::RuntimeClassBase, RuntimeClassT), \
2937 "'MixInHelper' macro can only be used with ::Windows::WRL::RuntimeClass types"); \
2939 !__is_base_of(IClassFactory, RuntimeClassT), \
2940 "Incorrect usage of IClassFactory interface. Make sure that your RuntimeClass doesn't implement " \
2941 "IClassFactory interface use ::Windows::WRL::ClassFactory instead or 'MixInHelper' macro is not used on " \
2942 "::Windows::WRL::ClassFactory"); \
2943 return RuntimeClassT::QueryInterface(riid, ppvObject); \
2945 STDMETHOD_(ULONG, Release)() \
2947 return RuntimeClassT::Release(); \
2949 STDMETHOD_(ULONG, AddRef)() \
2951 return RuntimeClassT::AddRef(); \
2957 #ifndef WrlCreatorMapIncludePragmaEx
2958 # define WrlCreatorMapIncludePragmaEx(className, group) \
2960 false, "It's required to include 'wrl/module.h' to be able to use 'WrlCreatorMapIncludePragmaEx' macro");
2963 #ifndef WrlCreatorMapIncludePragma
2964 # define WrlCreatorMapIncludePragma(className) \
2966 false, "It's required to include 'wrl/module.h' to be able to use 'WrlCreatorMapIncludePragma' macro");
2969 #ifndef ActivatableClassWithFactoryEx
2970 # define ActivatableClassWithFactoryEx(className, factory, groupId) \
2972 false, "It's required to include 'wrl/module.h' to be able to use 'ActivatableClassWithFactoryEx' macro");
2975 #ifndef ActivatableClassWithFactory
2976 # define ActivatableClassWithFactory(className, factory) \
2978 false, "It's required to include 'wrl/module.h' to be able to use 'ActivatableClassWithFactory' macro");
2981 #ifndef ActivatableClass
2982 # define ActivatableClass(className) \
2983 static_assert(false, "It's required to include 'wrl/module.h' to be able to use 'ActivatableClass' macro");
2986 #ifndef ActivatableStaticOnlyFactoryEx
2987 # define ActivatableStaticOnlyFactoryEx(factory, serverName) \
2990 "It's required to include 'wrl/module.h' to be able to use 'ActivatableStaticOnlyFactoryEx' macro");
2993 #ifndef ActivatableStaticOnlyFactory
2994 # define ActivatableStaticOnlyFactory(factory) \
2996 false, "It's required to include 'wrl/module.h' to be able to use 'ActivatableStaticOnlyFactory' macro");
2999 #ifndef CoCreatableClassWithFactoryEx
3000 # define CoCreatableClassWithFactoryEx(className, factory, groupId) \
3002 false, "It's required to include 'wrl/module.h' to be able to use 'CoCreatableClassWithFactory' macro");
3005 #ifndef CoCreatableClassWithFactory
3006 # define CoCreatableClassWithFactory(className, factory) \
3008 false, "It's required to include 'wrl/module.h' to be able to use 'CoCreatableClassWithFactory' macro");
3011 #ifndef CoCreatableClass
3012 # define CoCreatableClass(className) \
3013 static_assert(false, "It's required to include 'wrl/module.h' to be able to use 'CoCreatableClass' macro");
3016 #ifndef CoCreatableClassWrlCreatorMapInclude
3017 # define CoCreatableClassWrlCreatorMapInclude(className) \
3020 "It's required to include 'wrl/module.h' to be able to use 'CoCreatableClassWrlCreatorMapInclude' macro");
3023 #ifndef CoCreatableClassWrlCreatorMapIncludeEx
3024 # define CoCreatableClassWrlCreatorMapIncludeEx(className, groupId) \
3027 "It's required to include 'wrl/module.h' to be able to use 'CoCreatableClassWrlCreatorMapInclude' macro");
3030 #undef UnknownIncrementReference
3031 #undef UnknownDecrementReference
3032 #undef UnknownBarrierAfterInterlock
3033 #undef UnknownInterlockedCompareExchangePointer
3034 #undef UnknownInterlockedCompareExchangePointerForIncrement
3035 #undef UnknownInterlockedCompareExchangePointerForRelease
3041 # pragma warning(pop)
HRESULT As(Details::ComPtrRef< ComPtr< U >> p) const
Definition: client.h:300
void Attach(InterfaceType *other)
Definition: client.h:266
Definition: implements.h:115
Definition: implements.h:289
Definition: implements.h:396
Definition: implements.h:2734
void * Allocate()
Definition: implements.h:2748
void Detach()
Definition: implements.h:2764
~MakeAllocator()
Definition: implements.h:2740
MakeAllocator()
Definition: implements.h:2736
Definition: implements.h:184
_In_opt_z_ const wchar_t _In_z_ const wchar_t _Inout_ RO_REGISTRATION_COOKIE * cookie
Definition: implements.h:269
_In_opt_z_ const wchar_t _In_z_ const wchar_t _Inout_ RO_REGISTRATION_COOKIE unsigned int
Definition: implements.h:270
static volatile unsigned long objectCount_
Definition: implements.h:189
STDMETHOD_(const CreatorMap **, GetLastEntryPointer)() const
Definition: implements.h:256
_In_opt_z_ const wchar_t IID IClassFactory _Inout_ DWORD unsigned int
Definition: implements.h:273
virtual ~ModuleBase()
Definition: implements.h:225
STDMETHOD_(unsigned long, IncrementObjectCount)()=0
STDMETHOD_(SRWLOCK *, GetLock)() const
Definition: implements.h:261
ModuleBase & operator=(const ModuleBase &)=delete
STDMETHOD_(unsigned long, DecrementObjectCount)()=0
STDMETHOD_(const CreatorMap **, GetFirstEntryPointer)() const
Definition: implements.h:246
STDMETHOD_(unsigned long, GetObjectCount)() const
Definition: implements.h:241
ModuleBase()
Definition: implements.h:197
ModuleBase(const ModuleBase &)=delete
STDMETHOD_(const CreatorMap **, GetMidEntryPointer)() const
Definition: implements.h:251
_In_opt_z_ const wchar_t _In_z_ const wchar_t ** activatableClassIds
Definition: implements.h:267
static ModuleBase * module_
Definition: implements.h:195
Definition: implements.h:285
Definition: implements.h:311
HRESULT RuntimeClassInitialize()
Definition: implements.h:388
static HRESULT AsIID(T *implements, REFIID riid, void **ppvObject)
Definition: implements.h:314
static HRESULT GetImplementedIIDS(T *implements, ULONG *iidCount, _When_(*iidCount==0, _At_(*iids, _Post_null_)) _When_(*iidCount > 0, _At_(*iids, _Post_notnull_)) _Result_nullonfailure_ IID **iids)
Definition: implements.h:353
Definition: implements.h:306
RuntimeClassFlagsT ClassFlags
Definition: implements.h:1947
unsigned long InternalAddRef()
Definition: implements.h:2028
unsigned long GetRefCount() const
Definition: implements.h:2053
RuntimeClassImpl()
Definition: implements.h:2017
ULONG * iidCount
Definition: implements.h:1981
STDMETHOD_(ULONG, AddRef)()
Definition: implements.h:1957
STDMETHOD_(ULONG, Release)()
Definition: implements.h:1962
unsigned long InternalRelease()
Definition: implements.h:2036
virtual ~RuntimeClassImpl()
Definition: implements.h:2021
RuntimeClassFlagsT ClassFlags
Definition: implements.h:1814
STDMETHOD_(ULONG, Release)()
Definition: implements.h:1829
RuntimeClassImpl()
Definition: implements.h:1849
unsigned long GetRefCount() const
Definition: implements.h:1885
STDMETHOD_(ULONG, AddRef)()
Definition: implements.h:1824
unsigned long InternalAddRef()
Definition: implements.h:1860
virtual ~RuntimeClassImpl()
Definition: implements.h:1853
unsigned long InternalRelease()
Definition: implements.h:1868
unsigned long GetRefCount() const
Definition: implements.h:2552
virtual ~RuntimeClassImpl()
Definition: implements.h:2540
STDMETHOD_(ULONG, Release)()
Definition: implements.h:2254
RuntimeClassImpl()
Definition: implements.h:2236
unsigned long InternalRelease()
Definition: implements.h:2616
unsigned long InternalAddRef()
Definition: implements.h:2570
RuntimeClassFlagsT ClassFlags
Definition: implements.h:2234
STDMETHOD_(ULONG, AddRef)()
Definition: implements.h:2249
STDMETHOD() GetWeakReference(_Outptr_ IWeakReference **weakReference)
Definition: implements.h:2662
typename Details::AdjustImplements< RuntimeClassFlagsT, false, typename IInspectableInjector< I0 >::InspectableIfNeeded, I0, IWeakReferenceSource, TInterfaces... >::Type ImplementsHelper
Definition: implements.h:2318
ULONG * iidCount
Definition: implements.h:2273
HRESULT CustomQueryInterface(REFIID, void **, bool *handled)
Definition: implements.h:2406
Definition: implements.h:2379
Definition: implements.h:2063
unsigned long IncrementStrongReference()
Definition: implements.h:2076
unsigned long GetStrongReferenceCount()
Definition: implements.h:2095
unsigned long DecrementStrongReference()
Definition: implements.h:2081
StrongReference(long refCount=1)
Definition: implements.h:2065
~StrongReference()
Definition: implements.h:2069
long strongRefCount_
Definition: implements.h:2105
void SetStrongReference(unsigned long value)
Definition: implements.h:2100
Definition: implements.h:2488
REFIID riid
Definition: implements.h:2504
virtual ~WeakReferenceImpl()
Definition: implements.h:2500
WeakReferenceImpl(IUnknown *unk)
Definition: implements.h:2490
return hr
Definition: implements.h:2532
REFIID _Outptr_result_maybenull_ _Result_nullonfailure_ IInspectable ** ppvObject
Definition: implements.h:2505
HRESULT hr
Definition: implements.h:2530
Definition: implements.h:1510
IStream REFIID riid
Definition: implements.h:1587
IStream REFIID _In_opt_ void * pv
Definition: implements.h:1588
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv)
Definition: implements.h:1520
REFIID riid
Definition: implements.h:1553
REFIID _In_opt_ void * pv
Definition: implements.h:1554
IStream REFIID _In_opt_ void DWORD _Reserved_ void * pvDestContext
Definition: implements.h:1590
FtmBase()
Definition: implements.h:1535
REFIID _In_opt_ void DWORD _Reserved_ void DWORD mshlflags
Definition: implements.h:1557
static HRESULT CreateGlobalInterfaceTable(IGlobalInterfaceTable **git)
Definition: implements.h:1630
virtual ~FtmBase()=default
STDMETHOD() ReleaseMarshalData(IStream *pStm) override
Definition: implements.h:1612
::Microsoft::WRL::ComPtr< IMarshal > marshaller_
Definition: implements.h:1641
STDMETHOD() UnmarshalInterface(IStream *pStm, REFIID riid, _Outptr_ void **ppv) override
Definition: implements.h:1603
STDMETHOD() DisconnectObject(DWORD dwReserved) override
Definition: implements.h:1621
IStream REFIID _In_opt_ void DWORD dwDestContext
Definition: implements.h:1589
REFIID _In_opt_ void DWORD _Reserved_ void * pvDestContext
Definition: implements.h:1556
IStream * pStm
Definition: implements.h:1586
REFIID _In_opt_ void DWORD dwDestContext
Definition: implements.h:1555
HRESULT CustomQueryInterface(REFIID, void **, bool *handled)
Definition: implements.h:2464
RuntimeClass()
Definition: implements.h:2471
RuntimeClass RuntimeClassT
Definition: implements.h:2479
Definition: implements.h:2422
HRESULT CustomQueryInterface(REFIID, void **, bool *handled)
Definition: implements.h:2432
RuntimeClass RuntimeClassT
Definition: implements.h:2447
RuntimeClass()
Definition: implements.h:2439
#define WRT_NO_VTABLE
Definition: implements.h:59
#define __WRL_IMPLEMENTS_FTM_BASE__(flags)
Definition: internal.h:21
#define __WRL_ASSERT__(cond)
Definition: internal.h:13
ComPtr< T > Make(TArgs &&... args)
Definition: implements.h:2785
bool IsValueAPointerToWeakReference(INT_PTR value)
Definition: implements.h:2137
WeakReferenceImpl * CreateWeakReference(IUnknown *)
Definition: implements.h:2854
const UINT_PTR EncodeWeakReferencePointerFlag
Definition: implements.h:2123
const CreatorMap * __pobjectentryfirst
Definition: implements.h:168
INT_PTR EncodeWeakReferencePointer(Microsoft::WRL::Details::WeakReferenceImpl *value)
Definition: implements.h:2339
const CreatorMap * __pobjectentrylast
Definition: implements.h:179
struct WRT_NO_VTABLE MarkImplements
Definition: implements.h:840
T ReadValueFromPointerNoFence(const volatile T *value)
Definition: implements.h:2207
unsigned long SafeUnknownDecrementReference(long volatile &refcount)
Definition: implements.h:1782
HRESULT MakeAndInitialize(I **result, TArgs &&... args)
Definition: implements.h:2808
struct WRT_NO_VTABLE AdjustImplements
Definition: implements.h:871
class WRT_NO_VTABLE RuntimeClassImpl
Definition: implements.h:1753
Microsoft::WRL::Details::WeakReferenceImpl * DecodeWeakReferencePointer(INT_PTR value)
Definition: implements.h:2346
struct WRT_NO_VTABLE ImplementsHelper
Definition: implements.h:833
unsigned long SafeUnknownIncrementReference(long volatile &refcount)
Definition: implements.h:1763
const CreatorMap * __pobjectentrymid
Definition: implements.h:175
Details::ModuleBase * GetModuleBase()
Definition: implements.h:643
__declspec(selectany) const DelegateCheckMode DefaultDelegateCheckMode
RuntimeClassType
Definition: implements.h:78
@ InhibitWeakReference
Definition: implements.h:82
@ WinRt
Definition: implements.h:79
@ InhibitRoOriginateError
Definition: implements.h:85
@ InhibitFtmBase
Definition: implements.h:84
@ WinRtClassicComMix
Definition: implements.h:81
@ Delegate
Definition: implements.h:83
@ ClassicCom
Definition: implements.h:80
RuntimeClassFlags< WinRt|InhibitWeakReference > InhibitWeakReferencePolicy
Definition: implements.h:117
This file has no copyright assigned and is placed in the Public Domain.
Definition: client.h:26
Microsoft::WRL::ChainInterfaces< MixIn< DerivedType, BaseType, hasImplements >, I1, I2, I3, I4, I5, I6, I7, I8, I9 >::CanCastTo HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv)
Definition: implements.h:779
Microsoft::WRL::ChainInterfaces< MixIn< DerivedType, BaseType, hasImplements >, I1, I2, I3, I4, I5, I6, I7, I8, I9 >::CastToUnknown IUnknown * CastToUnknown()=delete
Microsoft::WRL::ChainInterfaces< MixIn< DerivedType, BaseType, hasImplements >, I1, I2, I3, I4, I5, I6, I7, I8, I9 >::Verify static void Verify()
Definition: implements.h:755
Definition: implements.h:662
static const unsigned long IidCount
Definition: implements.h:712
static void Verify()
Definition: implements.h:665
static void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:719
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv)
Definition: implements.h:689
IUnknown * CastToUnknown()
Definition: implements.h:707
Definition: implements.h:73
virtual ~CloakedIid()=default
ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, typename MarkImplements< I0, __is_base_of(ImplementsBase, I0)>::Type, Bases... > Type
Definition: implements.h:881
ImplementsHelper< RuntimeClassFlagsT, doStrictCheck > Type
Definition: implements.h:894
AdjustImplements< RuntimeClassFlagsT, doStrictCheck, Bases... >::Type Type
Definition: implements.h:888
Definition: implements.h:1256
static const bool value
Definition: implements.h:1257
Definition: implements.h:1897
IInspectable InspectableIfNeeded
Definition: implements.h:1927
Details::Nil InspectableIfNeeded
Definition: implements.h:1921
Definition: implements.h:1916
Definition: implements.h:98
Definition: implements.h:1101
unsigned long GetIidCount()
Definition: implements.h:1119
void FillArrayWithIid(_Inout_ unsigned long *, _Inout_ IID *)
Definition: implements.h:1124
HRESULT CanCastTo(REFIID, _Outptr_ void **, bool *=nullptr)
Definition: implements.h:1112
unsigned long GetIidCount()
Definition: implements.h:1348
ImplementsHelper()
Definition: implements.h:1362
ComPtr< FactoryInterface > GetComposableBaseFactory()
Definition: implements.h:1401
ComPtr< IInspectable > GetComposableBase()
Definition: implements.h:1396
IUnknown * CastToUnknown()
Definition: implements.h:1343
HRESULT SetComposableBasePointers(IInspectable *base, _In_opt_ FactoryInterface *baseFactory=nullptr)
Definition: implements.h:1376
~ImplementsHelper()
Definition: implements.h:1367
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated)
Definition: implements.h:1337
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1353
IUnknown * CastToUnknown()
Definition: implements.h:1234
unsigned long GetIidCount()
Definition: implements.h:1239
AdjustImplements< RuntimeClassFlagsT, true, TInterfaces... >::Type BaseType
Definition: implements.h:1216
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:1218
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1245
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:1292
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1316
unsigned long GetIidCount()
Definition: implements.h:1308
ImplementsHelper< RuntimeClassFlagsT, true, ComposableBase< FactoryInterface > > BaseType
Definition: implements.h:1290
IUnknown * CastToUnknown()
Definition: implements.h:1300
IUnknown * CastToUnknown()
Definition: implements.h:925
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:936
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:909
unsigned long GetIidCount()
Definition: implements.h:930
virtual ~ImplementsHelper()=default
IUnknown * CastToUnknown()
Definition: implements.h:991
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:980
Selector< I0, ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ImplementsMarker< I0 >, TInterfaces... > > CurrentType
Definition: implements.h:970
unsigned long GetIidCount()
Definition: implements.h:997
virtual ~ImplementsHelper()=default
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1003
Selector< typename AdjustImplements< RuntimeClassFlagsT, true, TInterfaces... >::Type, ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ImplementsMarker< I0 >, TInterfaces... > > BaseType
Definition: implements.h:974
void FillArrayWithIid(_Inout_ unsigned long *, _Inout_ IID *)
Definition: implements.h:1092
unsigned long GetIidCount()
Definition: implements.h:1087
AdjustImplements< RuntimeClassFlagsT, doStrictCheck, I0 >::Type CurrentType
Definition: implements.h:1072
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:1074
IUnknown * CastToUnknown()
Definition: implements.h:1081
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:1033
AdjustImplements< RuntimeClassFlagsT, doStrictCheck, I0 >::Type CurrentType
Definition: implements.h:1030
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1056
AdjustImplements< RuntimeClassFlagsT, true, I1, TInterfaces... >::Type BaseType
Definition: implements.h:1031
unsigned long GetIidCount()
Definition: implements.h:1051
IUnknown * CastToUnknown()
Definition: implements.h:1045
Microsoft::WRL::Details::ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ChainInterfaces< C0, C1, C2, C3, C4, C5, C6, C7, C8, C9 >, TInterfaces... >::BaseType AdjustImplements< RuntimeClassFlagsT, true, TInterfaces... >::Type BaseType
Definition: implements.h:1159
Microsoft::WRL::Details::ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ChainInterfaces< C0, C1, C2, C3, C4, C5, C6, C7, C8, C9 >, TInterfaces... >::CastToUnknown IUnknown * CastToUnknown()
Definition: implements.h:1175
Microsoft::WRL::Details::ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ChainInterfaces< C0, C1, C2, C3, C4, C5, C6, C7, C8, C9 >, TInterfaces... >::GetIidCount unsigned long GetIidCount()
Definition: implements.h:1180
Microsoft::WRL::Details::ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ChainInterfaces< C0, C1, C2, C3, C4, C5, C6, C7, C8, C9 >, TInterfaces... >::CanCastTo HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated=nullptr)
Definition: implements.h:1161
Microsoft::WRL::Details::ImplementsHelper< RuntimeClassFlagsT, doStrictCheck, ChainInterfaces< C0, C1, C2, C3, C4, C5, C6, C7, C8, C9 >, TInterfaces... >::FillArrayWithIid void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1185
Definition: implements.h:837
Definition: implements.h:2369
InterfaceListHelper< TInterfaces... > TypeT
Definition: implements.h:2370
static void Verify()
Definition: implements.h:559
static void FillArrayWithIid(_Inout_ unsigned long *, _Inout_ IID *)
Definition: implements.h:591
static Base * CastToBase(T *ptr)
Definition: implements.h:565
static IUnknown * CastToUnknown(T *ptr)
Definition: implements.h:571
_Success_(return==true) static bool CanCastTo(T *ptr
CloakedType Base
Definition: implements.h:555
static void FillArrayWithIid(_Inout_ unsigned long *, _Inout_ IID *)
Definition: implements.h:606
_Success_(return==true) static bool CanCastTo(T *
static void Verify()
Definition: implements.h:603
Nil Base
Definition: implements.h:599
Definition: implements.h:508
I0 Base
Definition: implements.h:509
static void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:544
static IUnknown * CastToUnknown(T *ptr)
Definition: implements.h:525
static void Verify()
Definition: implements.h:513
_Success_(return==true) static bool CanCastTo(T *ptr
static Base * CastToBase(T *ptr)
Definition: implements.h:519
Definition: internal.h:125
Definition: internal.h:66
CloakedIid< I0 > Type
Definition: implements.h:859
I0 Type
Definition: implements.h:845
ImplementsMarker< I0 > Type
Definition: implements.h:851
MixIn< DerivedType, BaseType, hasImplements > Type
Definition: implements.h:866
Definition: implements.h:948
static void Verify()
Definition: implements.h:633
Definition: implements.h:619
static void Verify()
Definition: implements.h:620
static void Verify()
Definition: implements.h:410
static void Verify()
Definition: implements.h:429
static void Verify()
Definition: implements.h:449
static void Verify()
Definition: implements.h:490
static void Verify()
Definition: implements.h:473
Definition: implements.h:404
static void OriginateError(HRESULT hr, HSTRING message)
Definition: implements.h:136
Definition: implements.h:121
static void OriginateError(HRESULT hr, HSTRING message)
Definition: implements.h:122
IUnknown * CastToUnknown()
Definition: implements.h:1486
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv)
Definition: implements.h:1481
RuntimeClassFlags< flags > ClassFlags
Definition: implements.h:1470
unsigned long GetIidCount()
Definition: implements.h:1491
Details::AdjustImplements< RuntimeClassFlags< flags >, true, I0, TInterfaces... >::Type BaseType
Definition: implements.h:1475
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1496
I0 FirstInterface
Definition: implements.h:1471
Definition: implements.h:1426
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv)
Definition: implements.h:1443
I0 FirstInterface
Definition: implements.h:1429
Details::AdjustImplements< RuntimeClassFlags< WinRt >, true, I0, TInterfaces... >::Type BaseType
Definition: implements.h:1437
RuntimeClassFlags< WinRt > ClassFlags
Definition: implements.h:1428
unsigned long GetIidCount()
Definition: implements.h:1453
virtual ~Implements()=default
void FillArrayWithIid(_Inout_ unsigned long *index, _Inout_ IID *iids)
Definition: implements.h:1458
IUnknown * CastToUnknown()
Definition: implements.h:1448
Definition: implements.h:109
Definition: implements.h:90
static const unsigned int value
Definition: implements.h:91
Definition: implements.h:2126
void * ifHighBitIsSetThenShiftLeftToYieldPointerToWeakReference
Definition: implements.h:2132
UINT_PTR refCount
Definition: implements.h:2128
INT_PTR rawValue
Definition: implements.h:2130
interface IWeakReferenceSource IWeakReferenceSource
Definition: weakreference.h:49
interface IWeakReference IWeakReference
Definition: weakreference.h:43