StoreContext::RequestPurchaseAsync reports "WinRT originate error - 0x80070578"

xinsb 1 Reputation point

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();

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"?

Universal Windows Platform (UWP)
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,290 questions
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,323 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
884 questions
{count} votes