這篇文章主要講解了“ VC++ win7下怎么實(shí)現(xiàn)WIFI共享工具”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“ VC++ win7下怎么實(shí)現(xiàn)WIFI共享工具”吧!
創(chuàng)新互聯(lián)2013年至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元崇陽做網(wǎng)站,已為上家服務(wù),為崇陽各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:13518219792
關(guān)于無線承載網(wǎng)絡(luò)
無線承載網(wǎng)絡(luò)(Wireless Hosted Network)是指安裝有無線局域網(wǎng)服務(wù)的Windows 7和Windows Server 2008 R2所提供的一種WLAN功能,具備兩項(xiàng)主要功能:
第一、把一個(gè)物理無線網(wǎng)卡虛擬化成一個(gè)或多個(gè)虛擬無線網(wǎng)卡,稱為虛擬的WiFi。
第二、借助無線網(wǎng)卡把當(dāng)前接網(wǎng)絡(luò)虛擬成為一個(gè)基于軟件的無線接入點(diǎn),稱為虛擬AP或軟AP。
=========================萬惡的分割線===========================
項(xiàng)目需要包含wlanapi.h 頭文件和wlanapi.lib 庫
備注:測試環(huán)境win7_64,建議關(guān)閉一些安全軟件,(比如我測試的時(shí)候忘了關(guān)comodo導(dǎo)致防火墻總是拒絕其他設(shè)備的連接)。
=============================================================
功能不復(fù)雜,用到的主要函數(shù)有下面幾個(gè)
1.調(diào)用WlanOpenHandled得到一個(gè)連接hClientHandle,下面的操作都要用到這個(gè)連接。當(dāng)然程序退出的時(shí)候記得調(diào)用WlanCloseHandle關(guān)閉這個(gè)連接。
DWORD WINAPI WlanOpenHandle( _In_ DWORD dwClientVersion, _Reserved_ PVOID pReserved, _Out_ PDWORD pdwNegotiatedVersion, _Out_ PHANDLE phClientHandle ); DWORD WINAPI WlanCloseHandle( _In_ HANDLE hClientHandle, _Reserved_ PVOID pReserved );
2.下面的函數(shù)用來設(shè)置承載網(wǎng)絡(luò)的一些屬性。
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 );typedef enum _WLAN_HOSTED_NETWORK_OPCODE { wlan_hosted_network_opcode_connection_settings, //設(shè)置一些連接屬性 wlan_hosted_network_opcode_security_settings, //設(shè)置安全屬性 wlan_hosted_network_opcode_station_profile, //query the wireless Hosted Network station profile wlan_hosted_network_opcode_enable //query or set the wireless Hosted Network enabled flag } WLAN_HOSTED_NETWORK_OPCODE, *PWLAN_HOSTED_NETWORK_OPCODE;
3.啟用和禁用無線承載網(wǎng)絡(luò)。
打開網(wǎng)絡(luò)和共享中心 單擊更改適配器設(shè)置,如果啟用了無線承載網(wǎng)絡(luò) 面板里面就會(huì)有描述為Microsoft Virtual WiFi Miniport Adapter的一個(gè)虛擬網(wǎng)卡。禁用之后這個(gè)虛擬網(wǎng)卡就會(huì)消失了。
當(dāng)然只有啟用了無線承載網(wǎng)絡(luò)才能分享wifi啦
DWORD WINAPI WlanHostedNetworkForceStart( _In_ HANDLE hClientHandle, _Out_opt_ PWLAN_HOSTED_NETWORK_REASON pFailReason, _Reserved_ PVOID pvReserved );
DWORD WINAPI WlanHostedNetworkForceStop( _In_ HANDLE hClientHandle, _Out_opt_ PWLAN_HOSTED_NETWORK_REASON pFailReason, _Reserved_ PVOID pvReserved );
4.連接和斷開網(wǎng)絡(luò)
DWORD WINAPI WlanHostedNetworkStartUsing( _In_ HANDLE hClientHandle, _Out_opt_ PWLAN_HOSTED_NETWORK_REASON pFailReason, _Reserved_ PVOID pvReserved );
DWORD WINAPI WlanHostedNetworkStopUsing( _In_ HANDLE hClientHandle, _Out_opt_ PWLAN_HOSTED_NETWORK_REASON pFailReason, _Reserved_ PVOID pvReserved );
5.用來查詢承載網(wǎng)絡(luò)的網(wǎng)絡(luò)狀況。
DWORD WINAPI WlanHostedNetworkQueryStatus( _In_ HANDLE hClientHandle, _Out_ PWLAN_HOSTED_NETWORK_STATUS *ppWlanHostedNetworkStatus, _Reserved_ PVOID pvReserved );
typedef struct _WLAN_HOSTED_NETWORK_STATUS { WLAN_HOSTED_NETWORK_STATE HostedNetworkState; GUID IPDeviceID; DOT11_MAC_ADDRESS wlanHostedNetworkBSSID; DOT11_PHY_TYPE dot11PhyType; ULONG ulChannelFrequency; DWORD dwNumberOfPeers; //已連接的節(jié)點(diǎn)數(shù)目 WLAN_HOSTED_NETWORK_PEER_STATE PeerList[1]; //存放節(jié)點(diǎn)信息的數(shù)組 } WLAN_HOSTED_NETWORK_STATUS, *PWLAN_HOSTED_NETWORK_STATUS; typedef struct _WLAN_HOSTED_NETWORK_PEER_STATE { DOT11_MAC_ADDRESS PeerMacAddress; //節(jié)點(diǎn)設(shè)備的MAC地址 WLAN_HOSTED_NETWORK_PEER_AUTH_STATE PeerAuthState; //節(jié)點(diǎn)的認(rèn)證狀態(tài) } WLAN_HOSTED_NETWORK_PEER_STATE, *PWLAN_HOSTED_NETWORK_PEER_STATE;
調(diào)用WlanHostedNetworkQueryStatus將得到一個(gè)WLAN_HOSTED_NETWORK_STATUS結(jié)構(gòu)體,就可以查詢一些網(wǎng)絡(luò)基本信息了,比如dwNumberOfPeers連接到這個(gè)網(wǎng)絡(luò)的節(jié)點(diǎn)數(shù),PeerList數(shù)組存放著對(duì)應(yīng)節(jié)點(diǎn)的詳細(xì)信息,包括MAC地址和認(rèn)證狀態(tài)。
6.用來設(shè)置密碼
注意密碼長度必須 大于8 小于63 否則會(huì)調(diào)用失敗
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 );
======================貼代碼==========================
//WIFIMAIN.h 實(shí)現(xiàn)文件 #pragma once #include#pragma comment(lib,"wlanapi.lib") // WIFIMAIN class WIFIMAIN : public CWnd { DECLARE_DYNAMIC(WIFIMAIN) public: WIFIMAIN(); virtual ~WIFIMAIN(); protected: DECLARE_MESSAGE_MAP() private: bool allow; bool start; HANDLE hClient; public: int Init(void); int AllowHostedNetWork(void); int DisallowHostedNetWork(void); int StartHostedNetWork(void); int StopHostedNetWork(void); bool isStart(void); bool isAllow(void); int Resume(void); int getpeernumber(void); int SetKEY(CString key); int SetSSID(CString ssidname); };
// WIFIMAIN.cpp : 實(shí)現(xiàn)文件 // #include "stdafx.h" #include "wifi共享1028.h" #include "WIFIMAIN.h" // WIFIMAIN IMPLEMENT_DYNAMIC(WIFIMAIN, CWnd) WIFIMAIN::WIFIMAIN() : allow(false) , start(false) { Init(); } WIFIMAIN::~WIFIMAIN() { StopHostedNetWork(); WlanCloseHandle(hClient, NULL); } BEGIN_MESSAGE_MAP(WIFIMAIN, CWnd) END_MESSAGE_MAP() // WIFIMAIN 消息處理程序 int WIFIMAIN::Init(void) { DWORD dwCurVersion = 0; DWORD dwResult = 0; dwResult = WlanOpenHandle(WLAN_API_VERSION, NULL, &dwCurVersion, &hClient); if( ERROR_SUCCESS != dwResult ) { return -1; } BOOL bIsAllow = true; WLAN_HOSTED_NETWORK_REASON dwFailedReason; dwResult = WlanHostedNetworkSetProperty(hClient, wlan_hosted_network_opcode_enable, sizeof(BOOL), &bIsAllow, &dwFailedReason, NULL); if( ERROR_SUCCESS != dwResult ) { return -2; } return 0; } int WIFIMAIN::AllowHostedNetWork(void) { PWLAN_HOSTED_NETWORK_REASON pFailReason = NULL; DWORD dwResult= 0; dwResult=WlanHostedNetworkForceStart(hClient,pFailReason,NULL); if( dwResult != ERROR_SUCCESS ) { return -1; } allow=true; return 0; } int WIFIMAIN::DisallowHostedNetWork(void) { PWLAN_HOSTED_NETWORK_REASON pFailReason = NULL; DWORD dwResult= 0; dwResult=WlanHostedNetworkForceStop(hClient,pFailReason,NULL); if( dwResult != ERROR_SUCCESS ) { return -1; } allow=false; return 0; } int WIFIMAIN::StartHostedNetWork(void) { PWLAN_HOSTED_NETWORK_REASON pFailReason = NULL; DWORD dwResult= 0; dwResult=WlanHostedNetworkStartUsing(hClient,pFailReason,NULL); if( dwResult != ERROR_SUCCESS ) { return -1; } start=true; return 0; } int WIFIMAIN::StopHostedNetWork(void) { PWLAN_HOSTED_NETWORK_REASON pFailReason = NULL; DWORD dwResult= 0; dwResult=WlanHostedNetworkStopUsing(hClient,pFailReason,NULL); if( dwResult != ERROR_SUCCESS ) { return -1; } start=false; return 0; } bool WIFIMAIN::isStart(void) { return start; } bool WIFIMAIN::isAllow(void) { return allow; } int WIFIMAIN::Resume(void) { DWORD dwResult = 0; BOOL bIsAllow = false; WLAN_HOSTED_NETWORK_REASON dwFailedReason; dwResult = WlanHostedNetworkSetProperty(hClient, wlan_hosted_network_opcode_enable, sizeof(BOOL), &bIsAllow, &dwFailedReason, NULL); if( ERROR_SUCCESS != dwResult ) { return -2; } return 0; } int WIFIMAIN::getpeernumber(void) { PWLAN_HOSTED_NETWORK_STATUS ppWlanHostedNetworkStatus=NULL; int retval = WlanHostedNetworkQueryStatus(hClient,&ppWlanHostedNetworkStatus,NULL); if( retval != ERROR_SUCCESS ){ return -1; } return ppWlanHostedNetworkStatus->dwNumberOfPeers; } int WIFIMAIN::SetKEY(CString key) { char chkey[64]; int index; for(index=0; index感謝各位的閱讀,以上就是“ VC++ win7下怎么實(shí)現(xiàn)WIFI共享工具”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì) VC++ win7下怎么實(shí)現(xiàn)WIFI共享工具這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
分享標(biāo)題:VC++win7下怎么實(shí)現(xiàn)WIFI共享工具
網(wǎng)頁URL:http://weahome.cn/article/iiggsi.html