question

Hell-7731 avatar image
0 Votes"
Hell-7731 asked Hell-7731 commented

How to check WiFi direct is open? By C++

I wanna check is WiFi direct is open. Then close it.
I can disable “Microsoft Wi-Fi Direct Virtual Adapter” to close WiFi direct feature. Are there other ways to achieve this?
I find "DEVPKEY_WiFiDirect_IsConnected" in wlanapi.h, but unkonw how to use it. Where can I find a sample program?

windows-apic++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Hell-7731

Could you please tell us what kind of project do you want to use? Win32? or UWP?

Here is a sample about Wi-Fi direct, I suggest you could refer to: https://docs.microsoft.com/en-us/samples/microsoft/windows-universal-samples/wifidirect/


0 Votes 0 ·

I want use Win32 project.
Thanks

0 Votes 0 ·

1 Answer

SongZhu-MSFT avatar image
0 Votes"
SongZhu-MSFT answered Hell-7731 commented

According to the MSDN, You can try to use `WFDOpenHandle` to obtain the handle of the Wi-Fi Direct service, and check whether the function can be called successfully to determine whether to start the service. Also you can use other APIs to implement other functions.

Some code:

 int main()
 {
     DWORD dwClientVersion = WFD_API_VERSION;
     DWORD pdwNegotiatedVersion = 0;
     HANDLE clientHandle = NULL;
     DWORD connHandleStatus = WFDOpenHandle(dwClientVersion, &pdwNegotiatedVersion, &clientHandle); // Opening Client Handle
     if (connHandleStatus == ERROR_SUCCESS)
     {
         ......
     }
     else
     {
         ......
     }
 }

You can also refer to this official example: Wi-Fi Direct Legacy Connection C++ WRL Demo


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks your answer.
'WFDOpenHandle' can obtain Wi-Fi Direct service's handle. But WFD* function looks like can't enum opened WiFi Hotspod?

Windows Settings -> Network & Internet -> Mobile hotsport
I want to check this feature is on or off. I guess it's WiFi Direct's feature. May be my way it's wrong?

0 Votes 0 ·

Yes, this is not relevant. If you want to check the hotsport status, you can use WinRT API, refer to this answer. If you want to solve it through Win32, you may be able to modify the registry to achieve this function, refer to this link.


1 Vote 1 ·

Thanks your reply. ;)
Best wish😊

0 Votes 0 ·