在桌面应用程序中创建“Windows.UI.Popups.MessageDialog”的WinRT失败

时间:2015-01-30 21:46:11

标签: c++ winapi windows-runtime desktop abi

任何想法为什么上面的代码无法创建类实例。我试图在Windows应用程序中使用WinRT,这里是代码片段,它失败的地方被评论为'!':

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

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

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
    CheckHresult(RoInitialize(RO_INIT_MULTITHREADED));

    static const wchar_t ClassName[] = L"Windows.UI.Popups.MessageDialog";

    HSTRING hClassStr, hStr;

    CheckHresult(WindowsCreateString(ClassName, sizeof(ClassName) / sizeof(ClassName[0]) - 1, &hClassStr));

    ABI::Windows::UI::Popups::IMessageDialog* pClass;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    CheckHresult(RoActivateInstance(hClassStr, (IInspectable**)&pClass)); //here it fails with E_NOTIMPL !!!!!!!!!!

    WindowsDeleteString(hClassStr);

    static const wchar_t msgTitleName [] = L"Metro Message Box!";

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

    CheckHresult(pClass->put_Title(hStr));

    WindowsDeleteString(hStr);

    static const wchar_t msgContent [] = L"Hello Metro.";

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

    CheckHresult(pClass->put_Content(hStr));

    WindowsDeleteString(hStr);

    CheckHresult(pClass->ShowAsync(nullptr));
}

我不知道为什么会这样。&#39;

编辑:

&#39; RoActivateInstance&#39;函数无法尝试激活名为'Windows.UI.Popups.MessageDialog'的类的实例,其HRESULT为&#39; E_NOTIMPL&#39;。

1 个答案:

答案 0 :(得分:0)

如果查看链接到的MSDN页面的底部,则表示最低支持客户端仅适用于Windows 8 应用商店

普通桌面程序不支持API。