12 #include <wrl\internal.h>
13 #include <wrl\client.h>
14 #include <wrl\implements.h>
15 #include <wrl\wrappers\corewrappers.h>
23 #ifdef ____x_Windows_CFoundation_CIDeferral_FWD_DEFINED__
30 typedef ::Windows::Foundation::IDeferral IDeferral;
31 typedef ::Windows::Foundation::IDeferralFactory IDeferralFactory;
32 typedef ::Windows::Foundation::IDeferralCompletedHandler IDeferralCompletedHandler;
49 template <DelegateCheckMode delegateCheckMode>
69 template <InvokeMode invokeModeValue>
76 template <InvokeMode invokeMode>
78 template <
typename TDelegateInterface,
typename EventSourceOptions>
84 template <
typename TDelegateInterface>
90 void*** pVT =
reinterpret_cast<void***
>(pDelegate);
96 template <
typename TMemberFunction>
99 static const int args = -1;
102 template <
typename TDelegateInterface>
103 struct ArgTraits<HRESULT (STDMETHODCALLTYPE TDelegateInterface::*)(void)>
108 template <
typename TDelegateInterface,
typename TArg1>
109 struct ArgTraits<HRESULT (STDMETHODCALLTYPE TDelegateInterface::*)(TArg1)>
115 template <
typename TDelegateInterface,
typename TArg1,
typename TArg2>
116 struct ArgTraits<HRESULT (STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2)>
123 template <
typename TDelegateInterface,
typename TArg1,
typename TArg2,
typename TArg3>
124 struct ArgTraits<HRESULT (STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3)>
132 template <
typename TDelegateInterface,
typename TArg1,
typename TArg2,
typename TArg3,
typename TArg4>
133 struct ArgTraits<HRESULT (STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3, TArg4)>
143 typename TDelegateInterface,
149 struct ArgTraits<HRESULT (STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3, TArg4, TArg5)>
160 typename TDelegateInterface,
168 STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6)>
180 typename TDelegateInterface,
189 STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7)>
202 typename TDelegateInterface,
212 STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8)>
226 typename TDelegateInterface,
237 STDMETHODCALLTYPE TDelegateInterface::*)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9)>
256 typename TDelegateInterface,
257 bool isImplements = std::is_base_of_v<ImplementsBase, TDelegateInterface>>
261 template <
typename TDelegateInterface>
266 static const int args = Traits::args;
271 "Delegate Invoke signature doesn't match. Possible reasons: wrong calling convention, wrong "
272 "returned type or passed too many parameters to 'Callback'");
276 template <
typename TDelegateInterface>
283 template <
typename TDelegateInterface,
typename TCallback,
unsigned int argCount>
286 template <
typename TDelegateInterface,
typename TCallback>
291 : callback_(callback)
301 template <
typename TDelegateInterface,
typename TCallback>
308 : callback_(callback)
311 STDMETHOD(Invoke)(
typename Traits::Arg1Type arg1)
318 template <
typename TDelegateInterface,
typename TCallback>
319 struct InvokeHelper<TDelegateInterface, TCallback, 2>
WrlSealed
325 : callback_(callback)
328 STDMETHOD(Invoke)(
typename Traits::Arg1Type arg1,
typename Traits::Arg2Type arg2)
335 template <
typename TDelegateInterface,
typename TCallback>
336 struct InvokeHelper<TDelegateInterface, TCallback, 3>
WrlSealed
342 : callback_(callback)
346 (
typename Traits::Arg1Type
arg1,
typename Traits::Arg2Type arg2,
typename Traits::Arg3Type arg3)
353 template <
typename TDelegateInterface,
typename TCallback>
354 struct InvokeHelper<TDelegateInterface, TCallback, 4>
WrlSealed
360 : callback_(callback)
364 (
typename Traits::Arg1Type arg1,
365 typename Traits::Arg2Type arg2,
366 typename Traits::Arg3Type arg3,
367 typename Traits::Arg4Type
arg4)
374 template <
typename TDelegateInterface,
typename TCallback>
375 struct InvokeHelper<TDelegateInterface, TCallback, 5>
WrlSealed
381 : callback_(callback)
385 (
typename Traits::Arg1Type arg1,
386 typename Traits::Arg2Type arg2,
387 typename Traits::Arg3Type arg3,
388 typename Traits::Arg4Type arg4,
389 typename Traits::Arg5Type
arg5)
392 callback_(arg1, arg2, arg3, arg4, arg5));
397 template <
typename TDelegateInterface,
typename TCallback>
398 struct InvokeHelper<TDelegateInterface, TCallback, 6>
WrlSealed
404 : callback_(callback)
408 (
typename Traits::Arg1Type arg1,
409 typename Traits::Arg2Type arg2,
410 typename Traits::Arg3Type arg3,
411 typename Traits::Arg4Type arg4,
412 typename Traits::Arg5Type arg5,
413 typename Traits::Arg6Type
arg6)
416 callback_(arg1, arg2, arg3, arg4, arg5, arg6));
421 template <
typename TDelegateInterface,
typename TCallback>
422 struct InvokeHelper<TDelegateInterface, TCallback, 7>
WrlSealed
428 : callback_(callback)
432 (
typename Traits::Arg1Type arg1,
433 typename Traits::Arg2Type arg2,
434 typename Traits::Arg3Type arg3,
435 typename Traits::Arg4Type arg4,
436 typename Traits::Arg5Type arg5,
437 typename Traits::Arg6Type arg6,
438 typename Traits::Arg7Type
arg7)
441 callback_(arg1, arg2, arg3, arg4, arg5, arg6, arg7));
446 template <
typename TDelegateInterface,
typename TCallback>
447 struct InvokeHelper<TDelegateInterface, TCallback, 8>
WrlSealed
453 : callback_(callback)
457 (
typename Traits::Arg1Type arg1,
458 typename Traits::Arg2Type arg2,
459 typename Traits::Arg3Type arg3,
460 typename Traits::Arg4Type arg4,
461 typename Traits::Arg5Type arg5,
462 typename Traits::Arg6Type arg6,
463 typename Traits::Arg7Type arg7,
464 typename Traits::Arg8Type
arg8)
467 callback_(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8));
472 template <
typename TDelegateInterface,
typename TCallback>
473 struct InvokeHelper<TDelegateInterface, TCallback, 9>
WrlSealed
479 : callback_(callback)
483 (
typename Traits::Arg1Type arg1,
484 typename Traits::Arg2Type arg2,
485 typename Traits::Arg3Type arg3,
486 typename Traits::Arg4Type arg4,
487 typename Traits::Arg5Type arg5,
488 typename Traits::Arg6Type arg6,
489 typename Traits::Arg7Type arg7,
490 typename Traits::Arg8Type arg8,
491 typename Traits::Arg9Type
arg9)
494 callback_(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9));
499 #ifdef NUI_WRL_AGILE_INVOKE
500 template <
typename TDelegateInterface,
unsigned int argCount>
501 struct AgileInvokeHelper;
503 template <
typename TDelegateInterface>
504 struct AgileInvokeHelper<TDelegateInterface, 0>
506 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
508 Microsoft::WRL::FtmBase>
513 HRESULT Initialize(_In_ TDelegateInterface* delegateInterface)
515 return Microsoft::WRL::AsAgile(delegateInterface, &_agileptr);
518 virtual HRESULT STDMETHODCALLTYPE Invoke()
520 ComPtr<TDelegateInterface> localDelegate;
522 HRESULT hr = _agileptr.CopyTo(localDelegate.GetAddressOf());
525 hr = localDelegate->Invoke();
534 template <
typename TDelegateInterface>
535 struct AgileInvokeHelper<TDelegateInterface, 1>
537 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
539 Microsoft::WRL::FtmBase>
544 HRESULT Initialize(_In_ TDelegateInterface* delegateInterface)
546 return Microsoft::WRL::AsAgile(delegateInterface, &_agileptr);
549 virtual HRESULT STDMETHODCALLTYPE Invoke(
typename Traits::Arg1Type arg1)
551 ComPtr<TDelegateInterface> localDelegate;
553 HRESULT hr = _agileptr.CopyTo(localDelegate.GetAddressOf());
556 hr = localDelegate->Invoke(arg1);
565 template <
typename TDelegateInterface>
566 struct AgileInvokeHelper<TDelegateInterface, 2>
568 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
570 Microsoft::WRL::FtmBase>
575 HRESULT Initialize(_In_ TDelegateInterface* delegateInterface)
577 return Microsoft::WRL::AsAgile(delegateInterface, &_agileptr);
580 virtual HRESULT STDMETHODCALLTYPE Invoke(
typename Traits::Arg1Type arg1,
typename Traits::Arg2Type arg2)
582 ComPtr<TDelegateInterface> localDelegate;
584 HRESULT hr = _agileptr.CopyTo(localDelegate.GetAddressOf());
587 hr = localDelegate->Invoke(arg1, arg2);
596 template <
typename TDelegateInterface>
597 struct AgileInvokeHelper<TDelegateInterface, 3>
599 Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>,
601 Microsoft::WRL::FtmBase>
606 HRESULT Initialize(_In_ TDelegateInterface* delegateInterface)
608 return Microsoft::WRL::AsAgile(delegateInterface, &_agileptr);
611 virtual HRESULT STDMETHODCALLTYPE
612 Invoke(
typename Traits::Arg1Type arg1,
typename Traits::Arg2Type arg2,
typename Traits::Arg3Type arg3)
614 ComPtr<TDelegateInterface> localDelegate;
616 HRESULT hr = _agileptr.CopyTo(localDelegate.GetAddressOf());
619 hr = localDelegate->Invoke(arg1, arg2, arg3);
628 template <
typename TDelegateInterface>
630 CreateAgileHelper(_In_ TDelegateInterface* delegateInterface, _COM_Outptr_ TDelegateInterface** wrapper)
633 ComPtr<AgileInvokeHelper<
639 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
640 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
642 invokeHelper =
Make<AgileInvokeHelper<
645 HRESULT hr = invokeHelper ? S_OK : E_OUTOFMEMORY;
648 hr = invokeHelper->Initialize(delegateInterface);
651 hr = invokeHelper.CopyTo(wrapper);
664 template <
typename TDelegateInterface,
typename TCallback>
668 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
669 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
673 InvokeHelper<TDelegateInterface, TCallback, Details::ArgTraitsHelper<TDelegateInterface>::args>>(
678 template <
typename TDelegateInterface,
typename TCallbackObject>
679 ComPtr<typename Details::ArgTraitsHelper<TDelegateInterface>::Interface>
680 Callback(_In_ TCallbackObject*
object, _In_ HRESULT (TCallbackObject::*method)()) throw()
683 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
684 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
687 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
691 ComObject(TCallbackObject*
object, HRESULT (TCallbackObject::*method)())
throw()
698 return (object_->*method_)();
701 TCallbackObject* object_;
702 HRESULT (TCallbackObject::*method_)();
705 return Make<ComObject>(
object, method);
708 template <
typename TDelegateInterface,
typename TCallbackObject,
typename TArg1>
709 ComPtr<typename Details::ArgTraitsHelper<TDelegateInterface>::Interface>
710 Callback(_In_ TCallbackObject*
object, _In_ HRESULT (TCallbackObject::*method)(TArg1))
throw()
713 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
714 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
717 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
720 "Argument 1 from object method doesn't match Invoke argument 1");
724 ComObject(TCallbackObject*
object, HRESULT (TCallbackObject::*method)(TArg1))
throw()
729 STDMETHOD(Invoke)(TArg1 arg1)
731 return (object_->*method_)(arg1);
734 TCallbackObject* object_;
735 HRESULT (TCallbackObject::*method_)(TArg1);
738 return Make<ComObject>(
object, method);
741 template <
typename TDelegateInterface,
typename TCallbackObject,
typename TArg1,
typename TArg2>
742 ComPtr<typename Details::ArgTraitsHelper<TDelegateInterface>::Interface>
743 Callback(_In_ TCallbackObject*
object, _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2))
throw()
746 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
747 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
750 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
753 "Argument 1 from object method doesn't match Invoke argument 1");
756 "Argument 2 from object method doesn't match Invoke argument 2");
760 ComObject(TCallbackObject*
object, HRESULT (TCallbackObject::*method)(TArg1, TArg2))
throw()
765 STDMETHOD(Invoke)(TArg1 arg1, TArg2 arg2)
767 return (object_->*method_)(arg1, arg2);
770 TCallbackObject* object_;
771 HRESULT (TCallbackObject::*method_)(TArg1, TArg2);
774 return Make<ComObject>(
object, method);
777 template <
typename TDelegateInterface,
typename TCallbackObject,
typename TArg1,
typename TArg2,
typename TArg3>
778 ComPtr<typename Details::ArgTraitsHelper<TDelegateInterface>::Interface>
779 Callback(_In_ TCallbackObject*
object, _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3))
throw()
782 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
783 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
786 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
789 "Argument 1 from object method doesn't match Invoke argument 1");
792 "Argument 2 from object method doesn't match Invoke argument 2");
795 "Argument 3 from object method doesn't match Invoke argument 3");
799 ComObject(TCallbackObject*
object, HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3))
throw()
804 STDMETHOD(Invoke)(TArg1 arg1, TArg2 arg2, TArg3 arg3)
806 return (object_->*method_)(arg1, arg2, arg3);
809 TCallbackObject* object_;
810 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3);
813 return Make<ComObject>(
object, method);
817 typename TDelegateInterface,
818 typename TCallbackObject,
824 _In_ TCallbackObject*
object,
825 _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4))
throw()
828 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
829 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
832 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
835 "Argument 1 from object method doesn't match Invoke argument 1");
838 "Argument 2 from object method doesn't match Invoke argument 2");
841 "Argument 3 from object method doesn't match Invoke argument 3");
844 "Argument 4 from object method doesn't match Invoke argument 4");
849 TCallbackObject*
object,
850 HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4))
throw()
855 STDMETHOD(Invoke)(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4)
857 return (object_->*method_)(arg1, arg2, arg3, arg4);
860 TCallbackObject* object_;
861 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3, TArg4);
864 return Make<ComObject>(
object, method);
868 typename TDelegateInterface,
869 typename TCallbackObject,
876 _In_ TCallbackObject*
object,
877 _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5))
throw()
880 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
881 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
884 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
887 "Argument 1 from object method doesn't match Invoke argument 1");
890 "Argument 2 from object method doesn't match Invoke argument 2");
893 "Argument 3 from object method doesn't match Invoke argument 3");
896 "Argument 4 from object method doesn't match Invoke argument 4");
899 "Argument 5 from object method doesn't match Invoke argument 5");
904 TCallbackObject*
object,
905 HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5))
throw()
910 STDMETHOD(Invoke)(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5)
912 return (object_->*method_)(arg1, arg2, arg3, arg4, arg5);
915 TCallbackObject* object_;
916 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3, TArg4, TArg5);
919 return Make<ComObject>(
object, method);
923 typename TDelegateInterface,
924 typename TCallbackObject,
932 _In_ TCallbackObject*
object,
933 _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6))
throw()
936 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
937 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
940 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
943 "Argument 1 from object method doesn't match Invoke argument 1");
946 "Argument 2 from object method doesn't match Invoke argument 2");
949 "Argument 3 from object method doesn't match Invoke argument 3");
952 "Argument 4 from object method doesn't match Invoke argument 4");
955 "Argument 5 from object method doesn't match Invoke argument 5");
958 "Argument 6 from object method doesn't match Invoke argument 6");
963 TCallbackObject*
object,
964 HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6))
throw()
969 STDMETHOD(Invoke)(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6)
971 return (object_->*method_)(arg1, arg2, arg3, arg4, arg5, arg6);
974 TCallbackObject* object_;
975 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6);
978 return Make<ComObject>(
object, method);
982 typename TDelegateInterface,
983 typename TCallbackObject,
992 _In_ TCallbackObject*
object,
993 _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7))
throw()
996 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
997 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
1000 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
1003 "Argument 1 from object method doesn't match Invoke argument 1");
1006 "Argument 2 from object method doesn't match Invoke argument 2");
1009 "Argument 3 from object method doesn't match Invoke argument 3");
1012 "Argument 4 from object method doesn't match Invoke argument 4");
1015 "Argument 5 from object method doesn't match Invoke argument 5");
1018 "Argument 6 from object method doesn't match Invoke argument 6");
1021 "Argument 7 from object method doesn't match Invoke argument 7");
1026 TCallbackObject*
object,
1027 HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7))
throw()
1032 STDMETHOD(Invoke)(TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7)
1034 return (object_->*method_)(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1037 TCallbackObject* object_;
1038 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7);
1041 return Make<ComObject>(
object, method);
1045 typename TDelegateInterface,
1046 typename TCallbackObject,
1056 _In_ TCallbackObject*
object,
1057 _In_ HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8))
throw()
1060 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
1061 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
1064 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
1067 "Argument 1 from object method doesn't match Invoke argument 1");
1070 "Argument 2 from object method doesn't match Invoke argument 2");
1073 "Argument 3 from object method doesn't match Invoke argument 3");
1076 "Argument 4 from object method doesn't match Invoke argument 4");
1079 "Argument 5 from object method doesn't match Invoke argument 5");
1082 "Argument 6 from object method doesn't match Invoke argument 6");
1085 "Argument 7 from object method doesn't match Invoke argument 7");
1088 "Argument 8 from object method doesn't match Invoke argument 8");
1093 TCallbackObject*
object,
1094 HRESULT (TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8))
throw()
1100 (TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4, TArg5 arg5, TArg6 arg6, TArg7 arg7, TArg8 arg8)
1102 return (object_->*method_)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
1105 TCallbackObject* object_;
1106 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8);
1109 return Make<ComObject>(
object, method);
1113 typename TDelegateInterface,
1114 typename TCallbackObject,
1125 _In_ TCallbackObject*
object,
1127 TCallbackObject::*method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9))
throw()
1130 __is_base_of(IUnknown, TDelegateInterface) && !__is_base_of(IInspectable, TDelegateInterface),
1131 "Delegates objects must be 'IUnknown' base and not 'IInspectable'");
1134 "Number of arguments on object method doesn't match number of arguments on Delegate::Invoke");
1137 "Argument 1 from object method doesn't match Invoke argument 1");
1140 "Argument 2 from object method doesn't match Invoke argument 2");
1143 "Argument 3 from object method doesn't match Invoke argument 3");
1146 "Argument 4 from object method doesn't match Invoke argument 4");
1149 "Argument 5 from object method doesn't match Invoke argument 5");
1152 "Argument 6 from object method doesn't match Invoke argument 6");
1155 "Argument 7 from object method doesn't match Invoke argument 7");
1158 "Argument 8 from object method doesn't match Invoke argument 8");
1161 "Argument 9 from object method doesn't match Invoke argument 9");
1166 TCallbackObject*
object,
1167 HRESULT (TCallbackObject::*
1168 method)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9))
throw()
1184 return (object_->*method_)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
1187 TCallbackObject* object_;
1188 HRESULT (TCallbackObject::*method_)(TArg1, TArg2, TArg3, TArg4, TArg5, TArg6, TArg7, TArg8, TArg9);
1191 return Make<ComObject>(
object, method);
1207 , bucketAssists_(
nullptr)
1213 bucketAssists_ =
new (std::nothrow)
void*[items];
1214 if (begin_ ==
nullptr || bucketAssists_ ==
nullptr)
1218 delete[] bucketAssists_;
1222 bucketAssists_ =
nullptr;
1224 return E_OUTOFMEMORY;
1235 delete[] bucketAssists_;
1250 AddTail(element,
nullptr);
1253 void AddTail(_In_ IUnknown* element,
void* bucketAssist)
throw()
1259 *(bucketAssists_ + (end_ - begin_)) = bucketAssist;
1265 return static_cast<size_t>(end_ - begin_);
1270 return bucketAssists_;
1275 return bucketAssists_ + (end_ - begin_);
1281 void** bucketAssists_;
1289 template <
typename TInvokeMethod,
typename TDelegateInterface>
1291 TInvokeMethod invokeOne,
1292 Details::EventTargetArray* targetArray,
1296 targets = targetArray;
1298 for (
auto element = targets->Begin(); element != targets->End(); element++)
1300 HRESULT hr = (invokeOne)(*element);
1305 if (hr == RPC_E_DISCONNECTED || hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) ||
1309 token.
value =
reinterpret_cast<__int64
>(element->Get());
1310 pEvent->Remove(token);
1321 template <
typename TInvokeMethod,
typename TDelegateInterface>
1323 TInvokeMethod invokeOne,
1324 Details::EventTargetArray* targetArray,
1329 targets = targetArray;
1331 for (
auto element = targets->Begin(); element != targets->End(); element++)
1333 hr = (invokeOne)(*element);
1335 if (hr == RPC_E_DISCONNECTED || hr == HRESULT_FROM_WIN32(RPC_S_SERVER_UNAVAILABLE) ||
1341 token.
value =
reinterpret_cast<__int64
>(element->Get());
1342 pEvent->Remove(token);
1355 #if (defined(BUILD_WINDOWS) && (NTDDI_VERSION >= NTDDI_WINBLUE))
1357 typename TDelegateInterface,
1358 typename TEventSourceOptions = InvokeModeOptions<ReportUnhandledOnFirstErrorWithWin8Quirk>>
1360 template <
typename TDelegateInterface,
typename TEventSourceOptions = InvokeModeOptions<FireAll>>
1372 if (delegateInterface ==
nullptr)
1374 return E_INVALIDARG;
1396 size_t availableSlots =
targets_->Length() - 1;
1397 bool removed =
false;
1399 if (availableSlots == 0)
1401 if (
reinterpret_cast<__int64
>(
targets_->Begin()->
Get()) == token.value)
1410 MakeAndInitialize<Details::EventTargetArray>(pNewList.
GetAddressOf(), availableSlots);
1416 void** bucketElement =
targets_->Begin_BucketAssists();
1418 for (
auto element =
targets_->Begin(); element !=
targets_->End(); element++)
1420 if (!removed && token.value ==
reinterpret_cast<__int64
>(element->Get()))
1429 if (availableSlots == 0)
1435 !removed &&
"Attempt to remove token that was not added to this EventSource<>");
1443 pNewList->AddTail(element->Get(), *bucketElement);
1479 Add(_In_opt_ TDelegateInterface* delegateInterface,
1480 _In_opt_
void* bucketAssist,
1484 if (delegateInterface ==
nullptr)
1486 return E_INVALIDARG;
1489 return AddInternal(delegateInterface, bucketAssist, token);
1493 HRESULT AddInternal(
1494 _In_ TDelegateInterface* delegateInterface,
1495 _In_opt_
void* bucketAssist,
1516 HRESULT hr = MakeAndInitialize<Details::EventTargetArray>(
1527 void** bucketElement =
targets_->Begin_BucketAssists();
1528 for (
auto element =
targets_->Begin(); element !=
targets_->End(); element++)
1534 pNewList->AddTail(element->Get(), *bucketElement);
1540 token->value =
reinterpret_cast<__int64
>(delegateInterface);
1544 pNewList->AddTail(delegateInterface, bucketAssist);
1570 template <
typename TInvokeMethod>
1571 _Check_return_ HRESULT DoInvoke(TInvokeMethod invokeOne)
throw()
1579 ComPtr<Details::EventTargetArray> targets;
1590 hr = InvokeTraits<TEventSourceOptions::invokeMode>::InvokeDelegates(invokeOne, targets.Get(),
this);
1599 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke();
1603 template <
typename T0>
1607 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0);
1611 template <
typename T0,
typename T1>
1615 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0, arg1);
1619 template <
typename T0,
typename T1,
typename T2>
1620 _Check_return_ HRESULT
InvokeAll(T0 arg0, T1 arg1, T2 arg2)
throw()
1623 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0, arg1, arg2);
1627 template <
typename T0,
typename T1,
typename T2,
typename T3>
1628 _Check_return_ HRESULT
InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3)
throw()
1631 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0, arg1, arg2, arg3);
1635 template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4>
1636 _Check_return_ HRESULT
InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
throw()
1638 return DoInvoke([arg0, arg1, arg2, arg3, arg4](
ComPtr<IUnknown>& p) -> HRESULT {
1639 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0, arg1, arg2, arg3, arg4);
1643 template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5>
1644 _Check_return_ HRESULT
InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
throw()
1646 return DoInvoke([arg0, arg1, arg2, arg3, arg4, arg5](
ComPtr<IUnknown>& p) -> HRESULT {
1647 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0, arg1, arg2, arg3, arg4, arg5);
1651 template <
typename T0,
typename T1,
typename T2,
typename T3,
typename T4,
typename T5,
typename T6>
1652 _Check_return_ HRESULT
InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
throw()
1654 return DoInvoke([arg0, arg1, arg2, arg3, arg4, arg5, arg6](
ComPtr<IUnknown>& p) -> HRESULT {
1655 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
1668 _Check_return_ HRESULT
1669 InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
throw()
1671 return DoInvoke([arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7](
ComPtr<IUnknown>& p) -> HRESULT {
1672 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(
1673 arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
1687 _Check_return_ HRESULT
1688 InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
throw()
1690 return DoInvoke([arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8](
ComPtr<IUnknown>& p) -> HRESULT {
1691 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(
1692 arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
1707 _Check_return_ HRESULT
1708 InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
throw()
1711 [arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9](
ComPtr<IUnknown>& p) -> HRESULT {
1712 return static_cast<TDelegateInterface*
>(p.
Get())->Invoke(
1713 arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
1728 #ifdef __windows2Efoundation_h__
1730 template <
typename TEventArgsInterface,
typename TEventArgsClass>
1731 class DeferrableEventArgs :
public TEventArgsInterface
1734 STDMETHOD(GetDeferral)(_COM_Outptr_ ::ABI::Windows::Foundation::IDeferral** result)
1741 ::RoOriginateError(E_ILLEGAL_METHOD_CALL,
nullptr);
1742 return E_ILLEGAL_METHOD_CALL;
1755 Microsoft::WRL::Callback<::ABI::Windows::Foundation::IDeferralCompletedHandler>([lifetime]() {
1756 return lifetime->Complete();
1758 if (callback ==
nullptr)
1760 return E_OUTOFMEMORY;
1764 hr = factory->Create(callback.Get(), &deferral);
1770 completionsRequired_++;
1771 return deferral.
CopyTo(result);
1776 void InvokeAllFinished()
1783 auto lockGuard = lock_.LockExclusive();
1785 invokeNeeded = (completionsRequired_ == 0);
1790 static_cast<TEventArgsClass*
>(
this)->InvokeCompleteHandler();
1795 _Requires_lock_not_held_(lock_) HRESULT Complete()
1802 auto lockGuard = lock_.LockExclusive();
1803 if (completionsRequired_ == 0)
1807 ::RoOriginateError(E_ILLEGAL_METHOD_CALL,
nullptr);
1808 return E_ILLEGAL_METHOD_CALL;
1810 completionsRequired_--;
1811 invokeNeeded = (raised_ && (completionsRequired_ == 0));
1816 static_cast<TEventArgsClass*
>(
this)->InvokeCompleteHandler();
1822 Wrappers::SRWLock lock_;
1823 _Guarded_by_(lock_)
bool raised_ =
false;
1824 _Guarded_by_(lock_)
long completionsRequired_ = 0;
1829 #ifdef NUI_WRL_AGILE_INVOKE
1830 # if defined(BUILD_WINDOWS)
1832 typename TDelegateInterface,
1833 typename TEventSourceOptions =
1837 typename TDelegateInterface,
1848 if (delegateInterface ==
nullptr)
1852 return E_INVALIDARG;
1856 HRESULT hr = Details::CreateAgileHelper<TDelegateInterface>(delegateInterface, &agileCallback);
1860 agileCallback.
Get(),
1875 #ifdef BUILD_WINDOWS
1876 # include <wrl\internalevent.h>
HRESULT CopyTo(InterfaceType **ptr) const
Definition: client.h:281
InterfaceType *const * GetAddressOf() const
Definition: client.h:243
InterfaceType * Get() const
Definition: client.h:223
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3)
Definition: event.h:1628
HRESULT Remove(EventRegistrationToken token)
Definition: event.h:1381
HRESULT Add(_In_opt_ TDelegateInterface *delegateInterface, _In_opt_ void *bucketAssist, _Out_ EventRegistrationToken *token)
Definition: event.h:1479
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
Definition: event.h:1636
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
Definition: event.h:1669
Wrappers::SRWLock addRemoveLock_
Definition: event.h:1725
Wrappers::SRWLock targetsPointerLock_
Definition: event.h:1724
size_t GetSize() const
Definition: event.h:1717
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1)
Definition: event.h:1612
EventSource()
Definition: event.h:1365
_Check_return_ HRESULT InvokeAll(T0 arg0)
Definition: event.h:1604
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
Definition: event.h:1644
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2)
Definition: event.h:1620
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
Definition: event.h:1708
ComPtr< Details::EventTargetArray > targets_
Definition: event.h:1723
HRESULT Add(_In_opt_ TDelegateInterface *delegateInterface, _Out_ EventRegistrationToken *token)
Definition: event.h:1369
_Check_return_ HRESULT InvokeAll()
Definition: event.h:1596
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
Definition: event.h:1688
_Check_return_ HRESULT InvokeAll(T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
Definition: event.h:1652
Definition: implements.h:2422
Definition: corewrappers.h:366
Definition: corewrappers.h:975
Definition: corewrappers.h:708
Details::SyncLockExclusive SyncLockExclusive
Definition: corewrappers.h:710
_Acquires_exclusive_lock_ return _Post_same_lock_ return SyncLockExclusive LockExclusive()
Definition: corewrappers.h:722
#define WrlSealed
Definition: event.h:18
#define __WRL_ASSERT__(cond)
Definition: internal.h:13
ComPtr< T > Make(TArgs &&... args)
Definition: implements.h:2785
void * GetDelegateBucketAssist(TDelegateInterface *pDelegate)
Definition: event.h:85
RemoveReference< T >::Type && Move(_Inout_ T &&arg)
Definition: internal.h:95
__declspec(selectany) const DelegateCheckMode DefaultDelegateCheckMode
ComPtr< typename Details::ArgTraitsHelper< TDelegateInterface >::Interface > Callback(TCallback callback)
Definition: event.h:665
InvokeMode
Definition: event.h:63
@ FireAll
Definition: event.h:65
@ StopOnFirstError
Definition: event.h:64
DelegateCheckMode
Definition: event.h:44
@ NoCheck
Definition: event.h:45
This file has no copyright assigned and is placed in the Public Domain.
Definition: client.h:26
HRESULT GetActivationFactory(HSTRING classid, ::Microsoft::WRL::Details::ComPtrRef< T > factory)
Definition: client.h:361
constexpr auto JSCRIPT_E_CANTEXECUTE
Definition: patch.h:4
Definition: eventtoken.h:44
__int64 value
Definition: eventtoken.h:45
static HRESULT CheckReturn(HRESULT hr)
Definition: event.h:55
ArgTraits< methodType > Traits
Definition: event.h:265
decltype(&TDelegateInterface::Invoke) typedef methodType
Definition: event.h:264
TDelegateInterface Interface
Definition: event.h:267
TArg5 Arg5Type
Definition: event.h:175
TArg6 Arg6Type
Definition: event.h:176
TArg2 Arg2Type
Definition: event.h:172
TArg3 Arg3Type
Definition: event.h:173
TArg1 Arg1Type
Definition: event.h:171
TArg4 Arg4Type
Definition: event.h:174
TArg7 Arg7Type
Definition: event.h:198
TArg2 Arg2Type
Definition: event.h:193
TArg1 Arg1Type
Definition: event.h:192
TArg6 Arg6Type
Definition: event.h:197
TArg4 Arg4Type
Definition: event.h:195
TArg5 Arg5Type
Definition: event.h:196
TArg3 Arg3Type
Definition: event.h:194
TArg8 Arg8Type
Definition: event.h:247
TArg2 Arg2Type
Definition: event.h:241
TArg4 Arg4Type
Definition: event.h:243
TArg7 Arg7Type
Definition: event.h:246
TArg6 Arg6Type
Definition: event.h:245
TArg3 Arg3Type
Definition: event.h:242
TArg5 Arg5Type
Definition: event.h:244
TArg1 Arg1Type
Definition: event.h:240
TArg9 Arg9Type
Definition: event.h:248
TArg1 Arg1Type
Definition: event.h:215
TArg7 Arg7Type
Definition: event.h:221
TArg8 Arg8Type
Definition: event.h:222
TArg5 Arg5Type
Definition: event.h:219
TArg3 Arg3Type
Definition: event.h:217
TArg4 Arg4Type
Definition: event.h:218
TArg2 Arg2Type
Definition: event.h:216
TArg6 Arg6Type
Definition: event.h:220
TArg4 Arg4Type
Definition: event.h:139
TArg3 Arg3Type
Definition: event.h:138
TArg1 Arg1Type
Definition: event.h:136
TArg2 Arg2Type
Definition: event.h:137
TArg4 Arg4Type
Definition: event.h:155
TArg1 Arg1Type
Definition: event.h:152
TArg2 Arg2Type
Definition: event.h:153
TArg3 Arg3Type
Definition: event.h:154
TArg5 Arg5Type
Definition: event.h:156
TArg1 Arg1Type
Definition: event.h:119
TArg2 Arg2Type
Definition: event.h:120
TArg1 Arg1Type
Definition: event.h:112
TArg3 Arg3Type
Definition: event.h:129
TArg1 Arg1Type
Definition: event.h:127
TArg2 Arg2Type
Definition: event.h:128
static const int args
Definition: event.h:99
Definition: internal.h:66
EventTargetArray()
Definition: event.h:1204
void AddTail(_In_ IUnknown *element)
Definition: event.h:1248
void ** Begin_BucketAssists()
Definition: event.h:1268
Traits::Arg1Type Traits::Arg2Type Traits::Arg3Type Traits::Arg4Type Traits::Arg5Type Traits::Arg6Type arg6
Definition: event.h:414
Traits::Arg1Type Traits::Arg2Type Traits::Arg3Type Traits::Arg4Type Traits::Arg5Type Traits::Arg6Type Traits::Arg7Type arg7
Definition: event.h:439
HRESULT RuntimeClassInitialize(size_t items)
Definition: event.h:1210
ArgTraitsHelper< TDelegateInterface >::Traits Traits
Definition: event.h:305
void AddTail(_In_ IUnknown *element, void *bucketAssist)
Definition: event.h:1253
void ** End_BucketAssists()
Definition: event.h:1273
~EventTargetArray()
Definition: event.h:1231
Traits::Arg1Type arg1
Definition: event.h:346
InvokeHelper(TCallback callback)
Definition: event.h:290
Traits::Arg1Type Traits::Arg2Type Traits::Arg3Type Traits::Arg4Type Traits::Arg5Type Traits::Arg6Type Traits::Arg7Type Traits::Arg8Type arg8
Definition: event.h:465
TCallback callback_
Definition: event.h:298
size_t Length()
Definition: event.h:1263
ComPtr< IUnknown > * End()
Definition: event.h:1243
Traits::Arg1Type Traits::Arg2Type Traits::Arg3Type Traits::Arg4Type Traits::Arg5Type arg5
Definition: event.h:390
Traits::Arg1Type Traits::Arg2Type Traits::Arg3Type Traits::Arg4Type Traits::Arg5Type Traits::Arg6Type Traits::Arg7Type Traits::Arg8Type Traits::Arg9Type arg9
Definition: event.h:492
ComPtr< IUnknown > * Begin()
Definition: event.h:1238
Traits::Arg1Type Traits::Arg2Type Traits::Arg3Type Traits::Arg4Type arg4
Definition: event.h:368
static const InvokeMode invokeMode
Definition: event.h:72
static HRESULT InvokeDelegates(TInvokeMethod invokeOne, Details::EventTargetArray *targetArray, EventSource< TDelegateInterface, InvokeModeOptions< FireAll >> *pEvent)
Definition: event.h:1290
static HRESULT InvokeDelegates(TInvokeMethod invokeOne, Details::EventTargetArray *targetArray, EventSource< TDelegateInterface, InvokeModeOptions< StopOnFirstError >> *pEvent)
Definition: event.h:1322