当试用许可证为Windows 10商店应用期满OfflineLicensesChanged事件从未提

2019-09-29 18:58发布

我想为我的Win32应用程序转换为UWP为Windows 10商店下面的代码。 该应用程序是根据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事件从未提出。

任何想法,我究竟做错了什么?

文章来源: OfflineLicensesChanged event is never raised when trial license expires for a Windows 10 Store app