I'm trying to use WiFiDirect API from Windows 10 SDK and implement the Connector scenario in Win32 Console App. I've already enabled C++/CX in basic Console app and integrated code from Microsoft's example on GitHub.
For now I can successfully discover devices and even connect and transfer data if the devices are already paired. But when I'm trying to pair them from scratch, FromIdAsync task ends up as Cancelled and the last line below throws an exception saying that "The remote procedure call failed."
WiFiDirectConnectionParameters^ connectionParams = ref new WiFiDirectConnectionParameters();
connectionParams->GroupOwnerIntent = (short)(wcstoul(txtGOIntent->Text->Data(), nullptr, 10));
// IMPORTANT: FromIdAsync needs to be called from the UI thread
concurrency::task<WiFiDirectDevice^> fromIdTask(WiFiDirectDevice::FromIdAsync(discoveredDevice->DeviceInfo->Id, connectionParams));
fromIdTask.then([this](concurrency::task<WiFiDirectDevice^> fromIdResultTask)
{
try
{
WiFiDirectDevice^ wfdDevice = fromIdResultTask.get();
I believe that it cannot show the popup with PIN entry, but how to overcome this?
[update] TH2 has been out for a while, so the custom device pairing API is what I was alluding to originally. There is a SDK sample as well that shows you how to do use it. Checkout scenario 9 in the sample.
To be clear, you can pair a device in an app in 3-4 ways:
Most of the APIs in Windows.Devices.Enumeration* are considered "dual" APIs meaning they work in an app container as well as in a medium IL win32 type process. The exceptions are APIs that generate UI (ie. #1, & #2), so in your scenario, only #3 will work in a desktop console app.
Before TH2, #2 from above would implicitly happen. The RPC call fails because a console app is not in an app container, so the shell can't inject a modal dialog.
[original response] Obviously this is a scenario that should work. You should look for better support for win32 app using WiFiDirect WinRT APIs in Threshold 2 which soon to be released to everyone. You can try it now with a flighted insider build of Windows 10. I think the scenario in your question should be working.
I recommend checking out the TH2 SDK whenever it comes out. Check to see if there are new APIs that can solve your problems. Ping me after it ships, and I can give you more details on how to manage WFD pairing.