How to manage Wifi through VC ++ and how to manage vcwifi

Source: Internet
Author: User

How to manage Wifi through VC ++ and how to manage vcwifi
VC ++ manage Wifi

Use the wlan native api to connect, disconnect, and enumerate Wi-Fi information.

Here, only the connected Wi-Fi is processed.

PS: The CSDN blog channel is actually getting worse and worse! Fuck!

Code
// Demo1.cpp: defines the entry point of the console application. // # Include "stdafx. h" # include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Pragma comment (lib, "ole32.lib") # pragma comment (lib, "wlanapi. lib ") void ssid2wchar (DOT11_SSID & pIn, WCHAR * pOut) {char tmp [33] = {0}; // for (int I = 0; I <pIn. uSSIDLength; I ++) // {// sprintf (tmp + I, "% 02X", pIn. ucSSID [I] & 0xFF); //} memcpy (tmp, pIn. ucSSID, pIn. uSSIDLength); MultiByteToWideChar (CP_ACP, 0, tmp, strlen (tmp), pOut, 65);} int main () {CoInitialize (NULL); DWORD dwResult = 0; DWORD dwCurVer Sion = 0; HANDLE hClient = NULL; WCHAR GuidString [48] = {0}; PWLAN_INTERFACE_INFO_LIST pIfList = NULL; dwResult = WlanOpenHandle (2, NULL, & dwCurVersion, & hClient ); if (dwResult! = ERROR_SUCCESS) {wprintf (L "open wlan error!: % U \ n ", dwResult); goto end;} WlanEnumInterfaces (hClient, NULL, & pIfList); // enumerate the StringFromGUID2 (pIfList-> InterfaceInfo [0]. interfaceGuid), (LPOLESTR) & GuidString, sizeof (GuidString)/sizeof (* GuidString); wprintf (L "Wlan nums: % u name [0]: % s GUID: % s \ n ", pIfList-> dwNumberOfItems, pIfList-> InterfaceInfo [0]. strInterfaceDescription, GuidString); // connect or disconnect wifi if (wlan_interface_state_connected = PIfList-> InterfaceInfo [0]. isState) {// WlanDisconnect (hClient, & pIfList-> InterfaceInfo [0]. interfaceGuid, NULL); // disconnect first} else if (wlan_interface_state_disconnected = pIfList-> InterfaceInfo [0]. isState) {WLAN_CONNECTION_PARAMETERS wlanConnPara; wlanConnPara. wlanConnectionMode = wlan_connection_mode_profile; // YES, we connect ap via the profile wlanConnPara. strProfile = L "Tami1703-5G "; // Set the profile name wlanConnPara. pDot11Ssid = NULL; // set ssid null wlanConnPara. dot11BssType = dot11_BSS_type_infrastructure; // dot11_BSS_type_any, I do not need it this time. wlanConnPara. pDesiredBssidList = NULL; // the desired BSSID list is empty wlanConnPara. dwFlags = WLAN_CONNECTION_HIDDEN_NETWORK; // it works on my WIN7 \ 8 WlanConnect (hClient, & (pIfList-> InterfaceInfo [0]. interfaceGuid ), & WlanConnPara, NULL); Sleep (2000);} // scan wifi skip, use hand // list wifi PWLAN_AVAILABLE_NETWORK_LIST pWifiList = NULL; dwResult = WlanGetAvailableNetworkList (hClient, & (pIfList-> InterfaceInfo [0]. interfaceGuid), numbers, NULL, & pWifiList); if (dwResult = ERROR_SUCCESS) {wprintf (L "Wifi Nums: % u \ n", pWifiList-> dwNumberOfItems ); for (int I = 0; I <PWifiList-> dwNumberOfItems; I ++) {WLAN_AVAILABLE_NETWORK oneWifi = pWifiList-> Network [I]; WCHAR pBuff [65] = {0}; ssid2wchar (oneWifi. dot11Ssid, pBuff); wprintf (L "[% d] Name: % s, \ t Qos: % u, SSID: % s \ n", I, lstrlen (oneWifi. strProfileName)> 0? OneWifi. strProfileName: L "null", oneWifi. wlanSignalQuality, pBuff) ;}end: system ("\ npause"); CoUninitialize (); return 0 ;}
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.