Issues with GetAppLicenseAsync in MFC C++ Application.

Ming Yu 20 Reputation points
2024-10-31T21:24:39.75+00:00

In the application, there is an MFC project and a Windows Runtime Component (Universal Windows) project, see my previous question (https://learn.microsoft.com/en-us/answers/questions/2105663/issues-with-requestpurchaseasync-in-mfc-c-applicat?comment=question#comment-1826305). Now, there is a new method in Class1 to check if User Has Subscription on addons, implemented as follows:

bool Class1::CheckIfUserHasSubscription()

{

Windows::Services::Store::StoreContext^ storeContext;

storeContext = StoreContext::GetDefault();

create_task(storeContext->GetAppLicenseAsync()).then([this](StoreAppLicense^ license)

{

    auto addOnLicenses = license->AddOnLicenses;

    for (const auto& addOnLicense : addOnLicenses)

    {

        if (addOnLicense->Value->IsActive)

            return true;

    }

}, task_continuation_context::get_current_winrt_context());

return false;

}

After using the RequestPurchaseAsync method to "purchase" a license, the CheckIfUserHasSubscription() method is called. Despite successfully purchasing, the method returns false. It appears that the loop "for (const auto& addOnLicense : addOnLicenses)" is not executed and the check in the loop is not performed. What could be the mistake? Thank you.

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

1 answer

Sort by: Most helpful
  1. Minxin Yu 12,001 Reputation points Microsoft Vendor
    2024-11-04T02:31:15.1933333+00:00

    Hi,

    Have you checked if addOnLicense->Value->IsActive value is true?

    create_task(...).then(...) is an asynchronous operation and does not block the function return false
    You can use get to wait for the result:

    bool WindowsRuntimeComponent1::Class1::CheckIfUserHasSubscription(){
    
    ......
    
    
    
     auto taskResult = create_task (
    ......
    
    
    
    
      if (addOnLicense->Value->IsActive)
    
    
            return true;
    
       else 
    
            return false;
    
    
    }, task_continuation_context::get_current_winrt_context ());
    
     initWindow->Release();  
    
      return taskResult.get ();
    }
    

    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.


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.