api - 如何用C++操作无线网卡开启共享热点WiFi?
巴扎黑
巴扎黑 2017-04-17 12:05:49
0
1
1097

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

巴扎黑
巴扎黑

membalas semua(1)
巴扎黑

首先需要笔记本具备AP热点功能,记得写好的程序必须用管理员身份运行。

准备工作需要先做好

//查看是否支持的承载网络
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

如果无法承载于正确的状态,在支持承载网络的情况下,除了重复开启外,就是驱动未启动。
所以要确定 microsoft托管网络虚拟适配器 为启动状态。
上面是开启的一个过程,下面是关闭。开启后记得关闭,不能开启再开启。

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

上面这种办法就是简单了,下面用API。

思路都是打开、配置、关闭三步走。

//打开句柄
WlanOpenHandle

DWORD WINAPI WlanOpenHandle(
  _In_       DWORD   dwClientVersion,
  _Reserved_ PVOID   pReserved,
  _Out_      PDWORD  pdwNegotiatedVersion,
  _Out_      PHANDLE phClientHandle
);

第二步: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
);

第一key是由系统生成的,你就可以不管了,我们需要设置第二keyWlanHostedNetworkSetSecondaryKey,也是我们在使用的密码。

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
);

关闭

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
);

忘说了,他们都是Wlanapi.h头文件的。

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan