WinRT - how to display Metro dialog box on a desktop app?

0

I believe this could be possible somehow because Windows PE loader already does it:

enter image description here

I tried directly creating an Windows.UI.Popups.MessageDialog class and instancing 'ShowAsync' but it fails with 'Element not found. (Exception from HRESULT: 0x80070490)'. I read this but I'm failing to create an Windows.UI.Core.CoreDispatcher like this:

#include <Roapi.h>
#include <Winstring.h>
#include <Windows.h>
#include <windows.ui.popups.h>
#include <windows.ui.core.h>
#include <windows.foundation.h>
#include <Unknwn.h>

inline void CheckHresult(HRESULT hr)
{
    if (FAILED(hr))
    {
        DebugBreak();
    }
}

struct WinRTString
{
    WinRTString() {}

    WinRTString(const WinRTString &) = delete;

    template<size_t tSizeCharArr>
    WinRTString(const wchar_t(&chArr)[tSizeCharArr])
    {
        *this = chArr;
    }

    template<size_t tSizeCharArr>
    WinRTString & operator= (const wchar_t(&chArr)[tSizeCharArr])
    {
        this->~WinRTString();

        CheckHresult(WindowsCreateString(chArr, sizeof(chArr) / sizeof(chArr[0]) - 1, &hStr));

        return *this;
    }

    operator HSTRING() { return hStr;  }

    ~WinRTString()
    {
        if (hStr)
            WindowsDeleteString(hStr);

        hStr = nullptr;
    }

    HSTRING hStr = nullptr;
};

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
    ABI::Windows::UI::Core::ICoreDispatcher *pUIDispatcher;

    CheckHresult(RoActivateInstance(WinRTString(L"Windows.UI.Core.CoreDispatcher"), (IInspectable**) &pUIDispatcher)); //fails
}

With 'RoActivateInstance' HINSTANCE of '0x80040154 : Class not registered'.

Any ideas how can I show equvilent message. I know that on msdn documentation it says that this API is only supported by Metro applications but then how is this message displayed on Desktop when 'This app can't run on your PC'?

c++
windows
windows-runtime
messagebox
abi

1 Answer

0

Desktop apps Windows Runtime classes lists the classes publicly available. The message box example cited must be using WRL to consume WinRT API as traditional COM with implementation details for internal use only.

answered on Stack Overflow Feb 2, 2015 by Chawathe Vipul S • edited Jun 20, 2020 by Community

User contributions licensed under CC BY-SA 3.0