问题
I'm trying the following code for my Win32 app converted to UWP for the Windows 10 Store. The app is posted in the store under a trial license for 7 days.
The goal of the code below is to receive a notification when the app's trial period expires:
#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();
}
I let the app run and waited for the license to expire, but OfflineLicensesChanged event was never raised.
Any idea what am I doing wrong?
来源:https://stackoverflow.com/questions/40209789/offlinelicenseschanged-event-is-never-raised-when-trial-license-expires-for-a-wi