【发布时间】:2015-12-11 13:30:00
【问题描述】:
我正在尝试使用 Windows 10 SDK 中的 WiFiDirect API 并在 Win32 控制台应用程序中实现连接器方案。我已经在基本控制台应用程序中启用了 C++/CX,并集成了来自 Microsoft's example on GitHub 的代码。
现在,如果设备已经配对,我可以成功发现设备,甚至可以连接和传输数据。但是当我尝试从头开始配对它们时,FromIdAsync 任务以 Canceled 结束,下面的最后一行抛出异常,提示 “远程过程调用失败。”
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();
我认为它无法显示带有 PIN 输入的弹出窗口,但是如何克服这个问题?
【问题讨论】:
-
据记载,
[MarshalingBehavior(Agile)]表示您不能从控制台模式应用程序调用它。没有什么“敏捷”的。 -
@HansPassant 这使得 WiFi Direct 完全无法从桌面应用程序中使用。我能做点什么吗?我不知道,也许从我的应用程序或其他技巧创建 UI 线程?
-
相当晦涩,我猜你需要用 this web page 中提到的 [Platform::STAThread] 来装饰 main()。从未尝试过。请记住,如果它决定显示一个弹出窗口,那么什么都不会发生,应该死锁。
标签: windows-runtime wifi-direct c++-cx