2

I want to use WinRT API for WiFi Direct from Windows 10 SDK in Win32 Console Application. I know about C++/CX (and even made some progress going that way), but still want to make it work without this extension.

My problem is that I can't activate IWifiDirectDevice interface (from ABI::Windows::Devices::WiFiDirect) to access IWifiDirectDeviceStatics that provides an GetDeviceSelector method.

HStringReference strDevice(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectDevice);

ComPtr<IInspectable> insp;
hr = RoActivateInstance(strDevice.Get(), insp.GetAddressOf());

This code ends up with E_NOTIMPL as a result. In Microsoft's example they used factories for activation, but ABI::Windows::Devices::WiFiDirect namespace has no factories.

Worth mentioning that IWifiDirectAdvertisementPublisher works just fine when activated the way I wrote before.

So how to activate IWifiDirectDevice from WRL?

Yrchgrchh
  • 169
  • 8

1 Answers1

3

Windows.Devices.WiFiDirect.WiFiDirectDevice is not an activatable class. You can see that by looking at windows.devices.wifidirect.idl.

You will need to use the static methods, e.g.:

HStringReference strDevice(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectDevice);

ComPtr<IWiFiDirectDeviceStatics> wiFiDirectDeviceStatics;
hr = Windows::Foundation::GetActivationFactory(
    strDevice.Get(),
    &wiFiDirectDeviceStatics);

ComPtr<IWiFiDirectDevice> wiFiDirectDevice;
ComPtr<IAsyncOperation<WiFiDirectDevice*>> asyncOperation;
hr = wiFiDirectDeviceStatics->FromIdAsync(deviceId.Get(), &asyncOperation);

Consider taking a look at the Wi-Fi Direct sample.

kiewic
  • 15,852
  • 13
  • 78
  • 101
  • 2
    That is so unclear(I mean API), to init WiFiDirectDeviceStatic I need to pass it to GetActivationFactory... I supposed that GetActivationFactory should produce a factory... – Yrchgrchh Sep 17 '15 at 16:37
  • 2
    @Yrchgrchh Yes, it's confusing. Sorry. GetActivationFactory is really GetStaticStuff, but the idea was that most of the time you are getting the factory, so they named it after what most people will use it for. – Raymond Chen Sep 17 '15 at 17:47