C++ Windows 通知:使用依赖模板名称



我目前正在尝试为 Windows 10 本机通知创建回调。我用于添加通知的代码如下所示:

notification->add_Dismissed(
Callback<Implements<RuntimeClassFlags<ClassicCom>,
ITypedEventHandler<ToastNotification*, ToastDismissedEventArgs*>>>(
[eventHandler, expirationTime](IToastNotification*, IToastDismissedEventArgs* e) {
ToastDismissalReason reason;
if (SUCCEEDED(e->get_Reason(&reason))) {
if (reason == ToastDismissalReason_UserCanceled &&
expirationTime &&
MyDateTime::Now() >= expirationTime
){
reason = ToastDismissalReason_TimedOut;
}
eventHandler->toastDismissed(static_cast<IWinToastHandler::WinToastDismissalReason>(reason));
}
return S_OK;
}).Get(), &dismissedToken);

其中notificationIToastNotification*eventHandler是我的自定义处理程序类。

但是,自上次Visual Studio更新以来,我收到以下错误:

c:program files (x86)windows kits10include10.0.17134.0winrtwrlevent.h(316): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'
c:program files (x86)windows kits10include10.0.17134.0winrtwrlevent.h(324): error C7510: 'Callback': use of dependent template name must be prefixed with 'template'

遵循错误消息引用的代码:

// Construct a COM/WinRT delegate (an object with an Invoke() method) from a lambda.
// Check the return from this function for null to detect out of memory (E_OUTOFMEMORY) failure case.
template<typename TDelegateInterface, typename TLambda>
ComPtr<typename Details::DelegateArgTraitsHelper<TDelegateInterface>::Interface> Callback(TLambda&& callback) throw()
{
using DelegateHelper = Details::DelegateArgTraitsHelper<TDelegateInterface>;
return DelegateHelper::Traits::Callback<TDelegateInterface, typename DelegateHelper::Interface>(Details::Forward<TLambda>(callback));
}
// Construct a COM/WinRT delegate, an object with an Invoke() method, from a raw function.
template<typename TDelegateInterface, typename TFunc> ComPtr<typename Details::DelegateArgTraitsHelper<TDelegateInterface>::Interface> Callback(_In_ TFunc* callback) throw()
{
using DelegateHelper = Details::DelegateArgTraitsHelper<TDelegateInterface>;
return DelegateHelper::Traits::Callback<TDelegateInterface, typename DelegateHelper::Interface>(
[=](auto&& ...args) {
return callback(Details::Forward<decltype(args)>(args)...);
});
}

老实说,我有任何想法,出了什么问题。自上次更新以来,此特定代码一直在工作(据我所知(。你能指出我的解决方案吗?

我知道它与依赖模板名称有关。但我不知道代码的哪一部分是错误的——如果是winrt中的某种错别字,或者他们最近改变了一些东西,我必须调整我的代码。

谢谢你的建议。

正如@Evg所指出的,他们可能做了一些更改,并且现在需要关键字template对于依赖的teplates。

如果有人想知道,这是event.h中的新代码,它似乎正在工作:

// Construct a COM/WinRT delegate (an object with an Invoke() method) from a lambda.
// Check the return from this function for null to detect out of memory (E_OUTOFMEMORY) failure case.
template<typename TDelegateInterface, typename TLambda>
ComPtr<typename Details::DelegateArgTraitsHelper<TDelegateInterface>::Interface> Callback(TLambda&& callback) throw()
{
using DelegateHelper = Details::DelegateArgTraitsHelper<TDelegateInterface>;
return DelegateHelper::Traits::template Callback<TDelegateInterface, typename DelegateHelper::Interface>(Details::Forward<TLambda>(callback));
}
// Construct a COM/WinRT delegate, an object with an Invoke() method, from a raw function.
template<typename TDelegateInterface, typename TFunc>
ComPtr<typename Details::DelegateArgTraitsHelper<TDelegateInterface>::Interface> Callback(_In_ TFunc* callback) throw()
{
using DelegateHelper = Details::DelegateArgTraitsHelper<TDelegateInterface>;
return DelegateHelper::Traits::template Callback<TDelegateInterface, typename DelegateHelper::Interface>(
[=](auto&& ...args)
{
return callback(Details::Forward<decltype(args)>(args)...);
});
}

最新更新