代码:
#include
#include
#include
#pragma comment(lib, "wlanapi.lib")
#pragma comment(lib, "ole32.lib")
using namespace std;
int main()
{
DWORD clientversion = 2;
DWORD negotiversion = 0;
HANDLE network;
PWLAN_INTERFACE_INFO_LIST interfacelit;
WLAN_HOSTED_NETWORK_OPCODE opcode;
PWLAN_HOSTED_NETWORK_REASON reason=NULL;
DOT11_SSID ssid;
UCHAR uu[32] = "sdfasd";
WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS SSID;
PWLAN_HOSTED_NETWORK_STATUS state=0;
BOOL b;
SSID.dwMaxNumberOfPeers = 1;
SSID.hostedNetworkSSID.ucSSID[32] = *uu;
SSID.hostedNetworkSSID.uSSIDLength = sizeof(uu);
if ( int ww=WlanOpenHandle(clientversion, NULL, &negotiversion, &network)!=ERROR_SUCCESS)
{
cout << "打开网卡失败" << endl;
return -1;
}
if (ERROR_SUCCESS != WlanEnumInterfaces(network, NULL, &interfacelit))
{
cout << "获取网卡失败" << endl;
return -1;
}
WlanHostedNetworkSetProperty(network, wlan_hosted_network_opcode_enable, sizeof(BOOL), &b, reason, NULL);
if (int ww = WlanHostedNetworkSetProperty(network, wlan_hosted_network_opcode_connection_settings, sizeof(WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS), &SSID, reason, NULL) != ERROR_SUCCESS)
{
cout << "WiFi设置失败" << endl;
return -1;
}
int ww = WlanHostedNetworkForceStart(network, reason, NULL);
DWORD passlen = 9;
PUCHAR pass = (PUCHAR)"12345678";
int n=WlanHostedNetworkSetSecondaryKey(network, passlen, pass, true, true, reason, NULL);
if (n != ERROR_SUCCESS)
{
cout << "密码设置错误" << endl;
return -1;
}
if (ERROR_SUCCESS != WlanHostedNetworkStartUsing(network, reason, NULL))
{
cout << "无线网络开启失败" << endl;
return -1;
}
while (true)
{
int nw=WlanHostedNetworkQueryStatus(network, &state, NULL);
}
WlanHostedNetworkForceStop(network, reason, NULL);
WlanHostedNetworkStopUsing(network, reason, NULL);
WlanCloseHandle(network,NULL);
return 0;
}