Issues with RequestPurchaseAsync in MFC C++ Application

Ming Yu 20 Reputation points
2024-10-17T17:29:05.5766667+00:00

An app has been published in the Partner Center, and an addon submission has been created. This is the addon subscription overview.

User's image

In the application, there is an MFC project and a Windows Runtime Component (Universal Windows) project, as depicted below.

User's image

The Class1 is declared as follows:

namespace WindowsRuntimeComponent1
{
    public ref class Class1 sealed
    {
    public:
        Class1();
        int Purchase();
    };
}

The method Purchase() is implemented as:

int Class1::Purchase()
{
    Windows::Services::Store::StoreContext^ storeContext;
    storeContext = StoreContext::GetDefault();    

    create_task(storeContext->RequestPurchaseAsync("myAddonStoreID")).then([](StorePurchaseResult^ result)
    {
        // .......
    }, task_continuation_context::get_current_winrt_context());
}

The program crashes at the line:

create_task(storeContext->RequestPurchaseAsync("myAddonStoreID")).then([](StorePurchaseResult^ result)

What mistakes could be causing this issue? Thank you very much.

C++
C++
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,758 questions
Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
344 questions
{count} votes

Accepted answer
  1. Minxin Yu 12,001 Reputation points Microsoft Vendor
    2024-10-25T07:01:48.1133333+00:00

    Hi,

    set desktop app and specific HWND:

    <AppContainerApplication>false</AppContainerApplication>

    <GenerateWindowsMetadata>true</GenerateWindowsMetadata>

    User's image

    WindowsRuntimeComponent1::Class1::Purchase ()
    {
        Windows::Services::Store::StoreContext^ storeContext;
        storeContext = Windows::Services::Store::StoreContext::GetDefault ();
        HWND hwnd = GetActiveWindow ();
      
        IInitializeWithWindow* initWindow = nullptr;
        HRESULT hr = reinterpret_cast<IUnknown*>(storeContext)->QueryInterface (IID_PPV_ARGS (&initWindow));
        if (SUCCEEDED (hr) )
        {
           
            initWindow->Initialize (hwnd);
         
            create_task (storeContext->RequestPurchaseAsync ("myAddonStoreID")).then ([](StorePurchaseResult^ result)
                                                                                      {
                                                                                          // .......
                                                                                      }, task_continuation_context::get_current_winrt_context ());
            initWindow->Release ();
           
        }
       
        
    }
    

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.