Calling WinRT::MiracastReceiver from a Desktop Application(Win32/C++), it's non support

249 views Asked by At

First, I use WinRT::MiracastReceiver(Win10 sdk) by "Windows Application Packaging Project" in Win32/C++ project. https://learn.microsoft.com/zh-tw/windows/msix/desktop/desktop-to-uwp-packaging-dot-net. So It already has package identity(Private Networks and Internet C/S capability).

And I check this API has DualApiPartition property, so the desktop app can call the WinRT API. https://learn.microsoft.com/zh-tw/windows/win32/apiindex/uwp-apis-callable-from-a-classic-desktop-app

When I start a MiracastReceiver session, I get the result MiracastNotSupported? How can I solve this?

When I put the same code in WinRT/UWP project, it's successful.

int main()
{
    winrt::init_apartment();

    receiver_ = MiracastReceiver();
    receiver_.StatusChanged( {&OnStatusChanged} );

    MiracastReceiverSettings settings = receiver_.GetDefaultSettings();

    settings.FriendlyName(L"MiracastReceiver.2020.1217");
    settings.AuthorizationMethod(MiracastReceiverAuthorizationMethod::None);
    settings.ModelName(receiver_.GetDefaultSettings().ModelName());
    settings.ModelNumber(receiver_.GetDefaultSettings().ModelNumber());
    settings.RequireAuthorizationFromKnownTransmitters(false);

    auto settings_sts = receiver_.DisconnectAllAndApplySettings(settings);

    session_ = receiver_.CreateSession(nullptr);
    session_.AllowConnectionTakeover(true);

    session_.ConnectionCreated( {&OnConnectionCreated} );
    session_.Disconnected( {&OnDisconnected} );
    session_.MediaSourceCreated( {&OnMediaSourceCreated} );

    MiracastReceiverSessionStartResult result = session_.Start();

    MiracastReceiverSessionStartStatus status = result.Status();

    std::wostringstream message;
    message << L"ClickHandler: session_.Start, status=" << (int)status << std::endl;
    OutputDebugString(message.str().c_str());

    system("PAUSE");
}

status = MiracastNotSupported

env:

  • Visual Studio 2017 v15.9.30
  • Win10 SDK 10.0.19041.0
  • Win10 OS 2004 (19041)
1

There are 1 answers

0
Jerker Olofsson On

I spent 8 hours on this exact problem, and eventually found out that if I compile the app as x64 instead of targeting [Any CPU] I could get it to work.