Initializing the StoreContext with a window handle in C++ RRS feed

  • Question

  • Hello,

    I am writing bindings for electron to access the StoreContext API from my application. Since some of the API's methods need to run on the UI thread, I am trying to initialize it with the HWND of my main window, but I am unable to get it to compile successfully.

    Here is the snippet in question:

    HWND hwnd = (HWND)handle;
    auto context = wrapper->_instance;
    IInitializeWithWindow* pIInitWithWindow;
    IInspectable* iInspect = reinterpret_cast<IInspectable*>(context);
    if (SUCCEEDED(iInspect->QueryInterface(IID_PPV_ARGS(&pIInitWithWindow))))

    The instance inside the wrapper is an instance of StoreContext retrieved using StoreContext::GetDefault()

    When compiling, I stumble upon this error: 'IInitializeWithWindow': no GUID has been associated with this object.

    I also tried this snippet that I found in a similar library: 

    auto initWindow = context.try_as<IInitializeWithWindow>();
    if (initWindow != nullptr) {

    But this tells me that The StoreContext class does not have a method called try_as.

    Anyone encountered a similar issue and found a solution?

    Best Regards,


    Wednesday, July 10, 2019 7:47 AM

All replies

  • Hi,

    I notice that you are using electron, so is it a pure C++ app or a electron app? In addition,ABI and WRL is a good start for you to start, you can check the code from SO to try to modify your code.

    Best regards,


    Thursday, July 11, 2019 9:44 AM
  • Hi,

    It is an electron app. I am creating NodeJS bindings in C++ to be able to call the StoreContext API from the main process of electron. I've got most things running, but to effectively request a purchase, the method must be called from a UI thread. I've seen people online having to initialize UWP APIs with the hwnd of their current window to be able to do that. And that's where I hit an issue.

    I looked into the link provided and I'm not sure ABI or WRL would help me for this issue.

    Best Regards,

    Tuesday, July 16, 2019 7:46 AM
  • Hi,

    About this issue,what we can help is to provide a native c++ way to achieve such a function.If you want to bring an interaction with electron,then need the electron vendor to help you complete.We are not actually familiar with electron.

    Best Regards,


    Wednesday, July 17, 2019 5:50 AM