十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要讲解了“ VC++ win7下怎么实现WIFI共享工具”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ VC++ win7下怎么实现WIFI共享工具”吧!
创新互联2013年至今,是专业互联网技术服务公司,拥有项目成都网站设计、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元崇阳做网站,已为上家服务,为崇阳各地企业和个人服务,联系电话:13518219792
关于无线承载网络
无线承载网络(Wireless Hosted Network)是指安装有无线局域网服务的Windows 7和Windows Server 2008 R2所提供的一种WLAN功能,具备两项主要功能:
第一、把一个物理无线网卡虚拟化成一个或多个虚拟无线网卡,称为虚拟的WiFi。
第二、借助无线网卡把当前接网络虚拟成为一个基于软件的无线接入点,称为虚拟AP或软AP。
=========================万恶的分割线===========================
项目需要包含wlanapi.h 头文件和wlanapi.lib 库
备注:测试环境win7_64,建议关闭一些安全软件,(比如我测试的时候忘了关comodo导致防火墙总是拒绝其他设备的连接)。
=============================================================
功能不复杂,用到的主要函数有下面几个
1.调用WlanOpenHandled得到一个连接hClientHandle,下面的操作都要用到这个连接。当然程序退出的时候记得调用WlanCloseHandle关闭这个连接。
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.下面的函数用来设置承载网络的一些属性。
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, //设置一些连接属性 wlan_hosted_network_opcode_security_settings, //设置安全属性 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.启用和禁用无线承载网络。
打开网络和共享中心 单击更改适配器设置,如果启用了无线承载网络 面板里面就会有描述为Microsoft Virtual WiFi Miniport Adapter的一个虚拟网卡。禁用之后这个虚拟网卡就会消失了。
当然只有启用了无线承载网络才能分享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.连接和断开网络
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.用来查询承载网络的网络状况。
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; //已连接的节点数目 WLAN_HOSTED_NETWORK_PEER_STATE PeerList[1]; //存放节点信息的数组 } WLAN_HOSTED_NETWORK_STATUS, *PWLAN_HOSTED_NETWORK_STATUS; typedef struct _WLAN_HOSTED_NETWORK_PEER_STATE { DOT11_MAC_ADDRESS PeerMacAddress; //节点设备的MAC地址 WLAN_HOSTED_NETWORK_PEER_AUTH_STATE PeerAuthState; //节点的认证状态 } WLAN_HOSTED_NETWORK_PEER_STATE, *PWLAN_HOSTED_NETWORK_PEER_STATE;
调用WlanHostedNetworkQueryStatus将得到一个WLAN_HOSTED_NETWORK_STATUS结构体,就可以查询一些网络基本信息了,比如dwNumberOfPeers连接到这个网络的节点数,PeerList数组存放着对应节点的详细信息,包括MAC地址和认证状态。
6.用来设置密码
注意密码长度必须 大于8 小于63 否则会调用失败
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 实现文件 #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 : 实现文件 // #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下怎么实现WIFI共享工具”的内容了,经过本文的学习后,相信大家对 VC++ win7下怎么实现WIFI共享工具这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
分享题目:VC++win7下怎么实现WIFI共享工具
文章地址:http://6mz.cn/article/iiggsi.html