search

Home  >  Q&A  >  body text

api - 如何用C++操作无线网卡开启共享热点WiFi?

如题。
猎豹WiFi,360WiFi又是怎么操作计算机无线网卡开启WiFi热点的呢?

巴扎黑巴扎黑2767 days ago1081

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 12:07:49

    First of all, the notebook needs to have AP hotspot function. Remember that the written program must be run as an administrator.

    Preparations need to be done first

    //查看是否支持的承载网络
    netsh wlan show drivers
    
    //设置网络模式为allow
    netsh wlan set hostednetwork mode=allow
    //设置wifi 热点的名称和密码
    netsh wlan set hostednetwork ssid=name key=password
    //开启已经创建好的wifi热点 
    netsh wlan start hostednetwork
    

    If it cannot be hosted in the correct state, and the hosting network is supported, in addition to repeatedly opening it, the driver is not started.
    So make sure the Microsoft Managed Network Virtual Adapter is enabled.
    The above is a process of opening, and the following is a process of closing. Remember to turn it off after turning it on, and cannot turn it on again.

    //关闭已经创建好的wifi热点 
    netsh wlan stop hostednetwork
    //设置网络模式disllow
    netsh wlan set hostednetwork mode=disallow
    

    The above method is simple, let’s use API below.

    The idea is to open, configure and close in three steps.

    //打开句柄
    WlanOpenHandle
    
    DWORD WINAPI WlanOpenHandle(
      _In_       DWORD   dwClientVersion,
      _Reserved_ PVOID   pReserved,
      _Out_      PDWORD  pdwNegotiatedVersion,
      _Out_      PHANDLE phClientHandle
    );
    

    Step 2: WlanHostedNetworkInitSettings, WlanHostedNetworkSetProperty

    //配置
    WlanHostedNetworkInitSettings
    
    The WlanHostedNetworkInitSettings function configures and persists to storage the network connection settings (SSID and maximum number of peers, for example) on the wireless Hosted Network if these settings are not already configured.
    
    DWORD WINAPI WlanHostedNetworkInitSettings(
      _In_       HANDLE                      hClientHandle,
      _Out_opt_  PWLAN_HOSTED_NETWORK_REASON pFailReason,
      _Reserved_ PVOID                       pvReserved
    );
    
    WlanHostedNetworkSetProperty
    
    The WlanHostedNetworkSetProperty function sets static properties of the wireless Hosted Network.
    
    DWORD WINAPI WlanHostedNetworkSetProperty(
      _In_       HANDLE                      hClientHandle,
      _In_       WLAN_HOSTED_NETWORK_OPCODE  OpCode,
      _In_       DWORD                       dwDataSize,
      _In_       PVOID                       pvData,
      _Out_opt_  PWLAN_HOSTED_NETWORK_REASON pFailReason,
      _Reserved_ PVOID                       pvReserved
    );
    

    The first key is generated by the system, you can ignore it. We need to set the second key WlanHostedNetworkSetSecondaryKey, which is also the password we are using.

    WlanHostedNetworkSetSecondaryKey
    
    The WlanHostedNetworkSetSecondaryKey function configures the secondary security key that will be used by the wireless Hosted Network.
    
    DWORD WINAPI WlanHostedNetworkSetSecondaryKey(
      _In_       HANDLE                      hClientHandle,
      _In_       DWORD                       dwKeyLength,
      _In_       PUCHAR                      pucKeyData,
      _In_       BOOL                        bIsPassPhrase,
      _In_       BOOL                        bPersistent,
      _Out_opt_  PWLAN_HOSTED_NETWORK_REASON pFailReason,
      _Reserved_ PVOID                       pvReserved
    );
    
    //开启AP
    WlanHostedNetworkForceStart function
    
    The WlanHostedNetworkForceStart function transitions the wireless Hosted Network to the wlan_hosted_network_active state without associating the request with the application's calling handle.
    
    DWORD WINAPI WlanHostedNetworkForceStart(
      _In_       HANDLE                      hClientHandle,
      _Out_opt_  PWLAN_HOSTED_NETWORK_REASON pFailReason,
      _Reserved_ PVOID                       pvReserved
    );
    
    //WlanHostedNetworkStartUsing
    WlanHostedNetworkStartUsing function
    The WlanHostedNetworkStartUsing function starts the wireless Hosted Network.
    
    DWORD WINAPI WlanHostedNetworkStartUsing(
      _In_       HANDLE                      hClientHandle,
      _Out_opt_  PWLAN_HOSTED_NETWORK_REASON pFailReason,
      _Reserved_ PVOID                       pvReserved
    );
    

    Close

    WlanHostedNetworkForceStop 
    The WlanHostedNetworkForceStop function transitions the wireless Hosted Network to the wlan_hosted_network_idle without associating the request with the application's calling handle.
    
    DWORD WINAPI WlanHostedNetworkForceStop(
      _In_       HANDLE                      hClientHandle,
      _Out_opt_  PWLAN_HOSTED_NETWORK_REASON pFailReason,
      _Reserved_ PVOID                       pvReserved
    );
    
    WlanCloseHandle
    The WlanCloseHandle function closes a connection to the server.
    
    
    DWORD WINAPI WlanCloseHandle(
      _In_       HANDLE hClientHandle,
      _Reserved_ PVOID  pReserved
    );
    

    Forgot to mention, they all belong to the Wlanapi.h header file.

    reply
    0
  • Cancelreply