1

I want to set up a WiFiDirect connect between 2 windows 10 in a console application not in a universal app.

  1. I set the target platform version to 10

    <TargetPlatformVersion>10.0</TargetPlatformVersion>

  2. I add the Reference to Windows.Foundation, Windows.Networking.Proximity, Windows.Networking.Sockets, Windows.Storage.Streams

In my application i check if WiFiDirect is suppartet.

        if ((Windows.Networking.Proximity.PeerFinder.SupportedDiscoveryTypes & Windows.Networking.Proximity.PeerDiscoveryTypes.Browse) != Windows.Networking.Proximity.PeerDiscoveryTypes.Browse)
        {
            Console.WriteLine("Peer discovery using Wifi-Direct is not supported.\n");

        }

This works as it should. But when i call PeerFinder.Start() i get a exception .

HRESULT 0x80004004(E_ABORT)

This is the code calling PeerFinder.Start()

        try
        {
            PeerFinder.AllowWiFiDirect = true;
            PeerFinder.Role = PeerRole.Peer;
            PeerFinder.ConnectionRequested += PeerFinder_ConnectionRequested;
            PeerFinder.TriggeredConnectionStateChanged += PeerFinder_TriggeredConnectionStateChanged;

            using (var discoveryDataWriter = new Windows.Storage.Streams.DataWriter(new Windows.Storage.Streams.InMemoryRandomAccessStream()))
            {
                discoveryDataWriter.WriteString("test12");
                PeerFinder.DiscoveryData = discoveryDataWriter.DetachBuffer();

            }

            PeerFinder.Start();
        }
        catch (Exception e)
        {
            Console.WriteLine("start failed: " + e.Message);
        }

i guess i can't use PeerFinder in a console application, are there any alternatives to establish a WiFiDirect connection for desktop applications?

P.Schnabel
  • 11
  • 2
  • You have to call "SetCurrentProcessExplicitAppUserModelID" API first. Fore more information, refer to this QA - https://social.msdn.microsoft.com/Forums/en-US/ce649545-9ec6-45da-a4ee-71b9f2bed156/using-metro-win8-sdk-to-build-desktop-style-application?forum=winappswithnativecode – SeongTae Jeong Oct 20 '16 at 04:47

0 Answers0