我們在XP上使用WZC和Vista上的本地WiFi,但是這裏是我們在Vista上使用的代碼,FWIW。
配置文件創建:
// open a handle to the service
if ((dwError = WlanOpenHandle(
WLAN_API_VERSION,
NULL, // reserved
&dwServiceVersion,
&hClient
)) != ERROR_SUCCESS)
{
hClient = NULL;
}
return dwError;
dwError=WlanSetProfile(hClient, &guid, 0, profile, NULL, TRUE, NULL, &reason_code);
建立連接:
WLAN_CONNECTION_PARAMETERS conn;
conn.wlanConnectionMode=wlan_connection_mode_profile;
conn.strProfile=name;
conn.pDot11Ssid=NULL;
conn.pDesiredBssidList=NULL;
conn.dot11BssType=dot11_BSS_type_independent;
conn.dwFlags=NULL;
dwError = WlanConnect(hClient, &guid, &conn, NULL);
檢查連接:
BOOL ret=FALSE;
DWORD dwError;
DWORD size;
void *p=NULL;
WLAN_INTERFACE_STATE *ps;
dwError = WlanQueryInterface(hClient, &guid, wlan_intf_opcode_interface_state, NULL, &size, &p, NULL);
ps=(WLAN_INTERFACE_STATE *)p;
if(dwError!=0)
ret=FALSE;
else
if(*ps==wlan_interface_state_connected)
ret=TRUE;
if(p!=NULL) WlanFreeMemory(p);
return ret;
爲了保持連接到網絡,就產生一個線程,然後繼續檢查進行連接,然後根據需要重新連接。
編輯:人這個標記的東西是跛腳。讓我喜歡3個編輯來讓事情正確。