StoreContext::RequestPurchaseAsync reports "WinRT originate error - 0x80070578"
I am trying to add IAP support to my win32 game, which is created by Cocos Creator 3.6.1.
I followed the code instruction in the store sample of "Windows-universal-samples":
storeContext = StoreContext::GetDefault();
create_task(storeContext->RequestPurchaseAsync(storeID)).then(=
{
this->OnPurchaseOperationDone(result->Status, storeID, orderID);
return S_OK;
});
An exception occurred when RequestPurchaseAsync:
info:StoreContextServer::Initialize: packageFullName = 18537XINStudio.DotH-_0.0.1.0_x64__9hnqqphhjcwwe, productStoreId = 9MXRPT2S0L5H, isLicensed = true, isAppContainer = false [Windows::Services::Store::Internal::StoreContextServer::Initialize]
info:Windows::Services::Store::StoreContext::RequestPurchaseAsync(9N5K99ZMCHTB) invoked. (CV:SL6M5gkelEu/CcDy.2.3) [Windows::Services::Store::StoreContext::RequestPurchaseAsync]
0x00007FF8BA20A839 (KernelBase.dll)处(位于 doth_cli.exe 中)引发的异常: WinRT originate error - 0x80070578 : 'This function must be called from a UI thread'。
“doth_cli.exe”(Win32): 已加载“C:\Windows\System32\CryptoWinRT.dll”。
I had thought the error was raised because it was called in non-UI thread. However, I still got the same error if I call RequestPurchaseAsync in UI thread, by creating a new thread with message loop and windows associated.
May I know what's the correct way to call "StoreContext::RequestPurchaseAsync"?