Giter Site home page Giter Site logo

mfc-winrt-storeapis's Introduction

MFC - WinRT - Store APIs

Description

This sample demonstrates how to call the WinRT Store APIs from an MFC application

To modify an existing MFC app to call WinRT Store APIs:

  1. Add the Microsoft.Windows.CppWinRT to your MFC app. This will help you access the Windows Runtime APIs. NuGet Gallery | Microsoft.Windows.CppWinRT 2.0.200615.7 microsoft/cppwinrt: C++ language projection for the Windows Runtime

  2. After installing the nuget package, make sure the MFC project properties are set to C++ version is ISO C++17, which is required by C++/WinRT:

  3. You will need to use the Windows.Services.Store API set as the namespace Windows.ApplicationModel.Store is not supported when running packaged as an MSIX app. Source: https://docs.microsoft.com/en-us/windows/uwp/monetize/in-app-purchases-and-trials

  4. If you haven’t done so already, you should reserve the application name in Partner Center: https://partner.microsoft.com/en-us/dashboard

  5. Use the Visual Studio Application Packaging Project to package the app as MSIX and provide the requires app identity and Store association. Package a desktop app from source code using Visual Studio - MSIX | Microsoft Docs. You should run and debug your application in the context of the Package Project to ensure it works as expected in this environment. Be sure to change the debug settings to Native only as it defaults to Managed and your breakpoints will not hit.

  6. Regarding initialization:

a. Be sure to call winrt::init_apartment(); in app start up.

b. Call IInitializeWithWindow.Initialize() from the StoreContext to associate the main window with the Microsoft Store UI. Here’s a code sample:

winrt::init_apartment();  
  
_storeContext = StoreContext::GetDefault();  
auto iwp = _storeContext.try_as<IInitializeWithWindow>();  
HWND hwnd = (HWND)GetMainWnd();  
auto hr = iwp->Initialize(hwnd);  
_com_error err(hr);  
AfxOutputDebugString(L"Init complete: " + (CString) err.ErrorMessage());  
  1. Then you can call the WinRT async calls which should be UI thread friendly without have to resort to creating worker threads to accomplish this task.

To Run

Click About icon – all work done in that handler. Note: You’ll want to associate it with your own app in Partner Center. In the sample, I've associated with an app I have in the Store.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.