我尝试使用以下代码将我的Win32应用程序转换为Windows 10商店的UWP。该应用程序根据试用许可证在商店中发布7天。
以下代码的目标是在应用试用期到期时收到通知:
#include <Windows.Services.Store.h>
#include <wrl.h>
#include <wrl/event.h>
//'hMainWnd' = HWND handle to the app's main window
//ComPtr<IStoreContextStatics> storeContextStatics;
//...
ComPtr<IStoreContext> storeContext;
hr = storeContextStatics->GetDefault(&storeContext);
if (SUCCEEDED(hr))
{
EventRegistrationToken tokenLicChanged;
hr = storeContext->add_OfflineLicensesChanged(Callback<__FITypedEventHandler_2_Windows__CServices__CStore__CStoreContext_IInspectable_t>(
[hMainWnd](IStoreContext* storeCntx, IInspectable* pDispArgs)->HRESULT
{
//Must be called when store license changes
::MessageBox(hMainWnd,
L"HELL YEAH -- LICENSE CHANGE NOTIFICATION!!!",
L"*****LIC CHANGE Result*****",
MB_ICONINFORMATION);
return S_OK;
}).Get(), &tokenLicChanged);
if (SUCCEEDED(hr))
{
//Put this thread into a waiting state...
}
else
{
__assert_and_fail();
}
}
else
{
__assert_and_fail();
}
我让应用程序运行并等待许可证到期,但OfflineLicensesChanged event从未被提升。
知道我做错了什么吗?