0

I am trying to display a Message Dialog in C++ (winrt) from a Desktop Windows App targeting Win 10 x64. The following code executes but the dialog is not shown. Return code from ShowAsync is good

int APIENTRY wWinMain(_In_ HINSTANCE    hInstance,
                         _In_opt_ HINSTANCE hPrevInstance,
                         _In_ LPWSTR        lpCmdLine,
                         _In_ int           nCmdShow)
    {

      Microsoft::WRL::Wrappers::RoInitializeWrapper init(RO_INIT_SINGLETHREADED);

        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialogFactory> messageDialogFactory;
        Microsoft::WRL::Wrappers::HStringReference messageDialogFactoryId(RuntimeClass_Windows_UI_Popups_MessageDialog);

        Windows::Foundation::GetActivationFactory(messageDialogFactoryId.Get(), messageDialogFactory.GetAddressOf());

        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IMessageDialog> messageDialog;
        Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::Windows::UI::Popups::IUICommand*>> uiCommands;

        messageDialogFactory->CreateWithTitle(Microsoft::WRL::Wrappers::HStringReference(L"XXX").Get(), Microsoft::WRL::Wrappers::HStringReference(L"YYY").Get(), messageDialog.GetAddressOf());
        messageDialog->get_Commands(uiCommands.GetAddressOf());

        Microsoft::WRL::ComPtr<ABI::Windows::UI::Popups::IUICommandFactory> uiCommandFactory;
        Microsoft::WRL::Wrappers::HStringReference commandFactoryId(RuntimeClass_Windows_UI_Popups_UICommand);

        Windows::Foundation::GetActivationFactory(commandFactoryId.Get(), uiCommandFactory.GetAddressOf());

        w::ComPtr<pu::IUICommand> button;
        uiCommandFactory->CreateWithHandler(Microsoft::WRL::Wrappers::HStringReference(L"ZZZ").Get(), new ButtonHandler(), button.GetAddressOf());

        uiCommands->Append(button.Get());

        Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::UI::Popups::IUICommand*>> showOperation;
        HRESULT hr = messageDialog->ShowAsync(showOperation.GetAddressOf());

        MSG msg;
        while( ::GetMessage(&msg, 0, 0, 0) > 0 )
        {
            ::TranslateMessage(&msg);
            ::DispatchMessage(&msg);
        }


      return 0;
    }
A Murray
  • 421
  • 1
  • 9
  • 15

1 Answers1

0

Should have read documentation - API doesn't have the DualApiPartitionAttribute

A Murray
  • 421
  • 1
  • 9
  • 15