VC++用wlanapi开展WIFI网络的获取与连接时,wlansetprofile和wlanConnect函数的使用

VC++用wlanapi进行WIFI网络的获取与连接时,wlansetprofile和wlanConnect函数的使用
本人近接着手于实现VC++调用wlanapi,实现WIFI网络的扫描获取以及选择其中一个进行连接,但是始终达不到所想要的效果,因此在这里求高人指点.关于wlanConnect与wlanSetProfile这两个的函数的使用方法,特别是后一个,以及wlanSetProfile函数的,关于wifi加密认证方式的xml文件的细则,就是wlanSetProfile函数的中第四个参数:strProfileXml

------解决方案--------------------
我也在找这个内容
WlanSetProfile 这个方法如何创建一个新的wifi热点呢?
不过我大概知道第4个参数是这样的
strProfileXml = "<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>11111</name><SSIDConfig><SSID><name>11111</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>WEP</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>networkKey</keyType><protected>false</protected><keyMaterial>11111</keyMaterial></sharedKey><keyIndex>0</keyIndex></security></MSM></WLANProfile>";

------解决方案--------------------
贴代码了,好害怕啊
头文件
C/C++ code
#ifndef _WIFI_SEARCH_CONNECTION_H_
#define _WIFI_SEARCH_CONNECTION_H_

#define WM_WLAN_NOTIFICATION        WM_USER+200 

#define DOT11_SSID_MAX_LENGTH 32
#define WLAN_MAX_PHY_TYPE_NUMBER 8
#define WLAN_MAX_NAME_LENGTH 256

class WifiConnection
{
    public:
        WifiConnection();

        ~WifiConnection();

    private:
        typedef enum _WLAN_INTERFACE_STATE
        {
            wlan_interface_state_not_ready = 0,
            wlan_interface_state_connected = 1,
            wlan_interface_state_ad_hoc_network_formed = 2,
            wlan_interface_state_disconnecting = 3,
            wlan_interface_state_disconnected = 4,
            wlan_interface_state_associating = 5,
            wlan_interface_state_discovering = 6,
            wlan_interface_state_authenticating =7
        }WLAN_INTERFACE_STATE, *PWLAN_INTERFACE_STATE;

        typedef struct _WLAN_INTERFACE_INFO
        {
            GUID InterfaceGuid;
            WCHAR strInterfaceDescription[256];
            WLAN_INTERFACE_STATE isState;
        }WLAN_INTERFACE_INFO,*PWLAN_INTERFACE_INFO;

        typedef struct _WLAN_INTERFACE_INFO_LIST
        {
            DWORD dwNumberOfItems;
            DWORD dwIndex;
            WLAN_INTERFACE_INFO InterfaceInfo[];
        }WLAN_INTERFACE_INFO_LIST, *PWLAN_INTERFACE_INFO_LIST;

        typedef struct _DOT11_SSID 
        {
            ULONG uSSIDLength;
            UCHAR ucSSID[DOT11_SSID_MAX_LENGTH];
        }DOT11_SSID, *PDOT11_SSID;

        typedef enum _DOT11_BSS_TYPE 
        {
            dot11_BSS_type_infrastructure   = 1,
            dot11_BSS_type_independent      = 2,
            dot11_BSS_type_any              = 3 
        }DOT11_BSS_TYPE, *PDOT11_BSS_TYPE;

        typedef DWORD WLAN_REASON_CODE, *PWLAN_REASON_CODE;

        typedef enum _DOT11_PHY_TYPE 
        {
            dot11_phy_type_unknown      = 0,
            dot11_phy_type_any          = 0,
            dot11_phy_type_fhss         = 1,
            dot11_phy_type_dsss         = 2,
            dot11_phy_type_irbaseband   = 3,
            dot11_phy_type_ofdm         = 4,
            dot11_phy_type_hrdsss       = 5,
            dot11_phy_type_erp          = 6,
            dot11_phy_type_ht           = 7,
            dot11_phy_type_IHV_start    = 0x80000000,
            dot11_phy_type_IHV_end      = 0xffffffff 
        }DOT11_PHY_TYPE, *PDOT11_PHY_TYPE;

        typedef ULONG WLAN_SIGNAL_QUALITY, *PWLAN_SIGNAL_QUALITY;

        typedef enum _DOT11_AUTH_ALGORITHM 
        {
          DOT11_AUTH_ALGO_80211_OPEN         = 1,
          DOT11_AUTH_ALGO_80211_SHARED_KEY   = 2,
          DOT11_AUTH_ALGO_WPA                = 3,
          DOT11_AUTH_ALGO_WPA_PSK            = 4,
          DOT11_AUTH_ALGO_WPA_NONE           = 5,
          DOT11_AUTH_ALGO_RSNA               = 6,
          DOT11_AUTH_ALGO_RSNA_PSK           = 7,
          DOT11_AUTH_ALGO_IHV_START          = 0x80000000,
          DOT11_AUTH_ALGO_IHV_END            = 0xffffffff
        } DOT11_AUTH_ALGORITHM, *PDOT11_AUTH_ALGORITHM;

        typedef enum _DOT11_CIPHER_ALGORITHM 
        {
          DOT11_CIPHER_ALGO_NONE            = 0x00,
          DOT11_CIPHER_ALGO_WEP40           = 0x01,
          DOT11_CIPHER_ALGO_TKIP            = 0x02,
          DOT11_CIPHER_ALGO_CCMP            = 0x04,
          DOT11_CIPHER_ALGO_WEP104          = 0x05,
          DOT11_CIPHER_ALGO_WPA_USE_GROUP   = 0x100,
          DOT11_CIPHER_ALGO_RSN_USE_GROUP   = 0x100,
          DOT11_CIPHER_ALGO_WEP             = 0x101,
          DOT11_CIPHER_ALGO_IHV_START       = 0x80000000,
          DOT11_CIPHER_ALGO_IHV_END         = 0xffffffff
        } DOT11_CIPHER_ALGORITHM, *PDOT11_CIPHER_ALGORITHM;

        typedef struct _WLAN_AVAILABLE_NETWORK 
        {
          WCHAR                  strProfileName[256];
          DOT11_SSID             dot11Ssid;
          DOT11_BSS_TYPE         dot11BssType;
          ULONG                  uNumberOfBssids;
          BOOL                   bNetworkConnectable;
          WLAN_REASON_CODE       wlanNotConnectableReason;
          ULONG                  uNumberOfPhyTypes;
          DOT11_PHY_TYPE         dot11PhyTypes[WLAN_MAX_PHY_TYPE_NUMBER];
          BOOL                   bMorePhyTypes;
          WLAN_SIGNAL_QUALITY    wlanSignalQuality;
          BOOL                   bSecurityEnabled;
          DOT11_AUTH_ALGORITHM   dot11DefaultAuthAlgorithm;
          DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm;
          DWORD                  dwFlags;
          DWORD                  dwReserved;
        }WLAN_AVAILABLE_NETWORK, *PWLAN_AVAILABLE_NETWORK;


        typedef struct _WLAN_AVAILABLE_NETWORK_LIST 
        {
            DWORD                  dwNumberOfItems;
            DWORD                  dwIndex;
            WLAN_AVAILABLE_NETWORK Network[1];
        }WLAN_AVAILABLE_NETWORK_LIST, *PWLAN_AVAILABLE_NETWORK_LIST;

        typedef struct _WLAN_PROFILE_INFO 
        {
            WCHAR strProfileName[256];
            DWORD dwFlags;
        } WLAN_PROFILE_INFO, *PWLAN_PROFILE_INFO;


        typedef struct _WLAN_PROFILE_INFO_LIST 
        {
            DWORD             dwNumberOfItems;
            DWORD             dwIndex;
            WLAN_PROFILE_INFO ProfileInfo[1];
        } WLAN_PROFILE_INFO_LIST, *PWLAN_PROFILE_INFO_LIST;

        typedef enum _WLAN_CONNECTION_MODE 
        {
          wlan_connection_mode_profile,
          wlan_connection_mode_temporary_profile,
          wlan_connection_mode_discovery_secure,
          wlan_connection_mode_discovery_unsecure,
          wlan_connection_mode_auto,
          wlan_connection_mode_invalid 
        } WLAN_CONNECTION_MODE, *PWLAN_CONNECTION_MODE;

        #define NDIS_OBJECT_TYPE_DEFAULT 0x80
        #define DOT11_BSSID_LIST_REVISION_1 1

        typedef struct _NDIS_OBJECT_HEADER 
        {
          UCHAR  Type;
          UCHAR  Revision;
          USHORT Size;
        } NDIS_OBJECT_HEADER, *PNDIS_OBJECT_HEADER;

        typedef UCHAR DOT11_MAC_ADDRESS[6];
        typedef DOT11_MAC_ADDRESS *PDOT11_MAC_ADDRESS;

        typedef struct _DOT11_BSSID_LIST 
        {
          NDIS_OBJECT_HEADER Header;
          ULONG              uNumOfEntries;
          ULONG              uTotalNumOfEntries;
          DOT11_MAC_ADDRESS  BSSIDs[1];
        } DOT11_BSSID_LIST, *PDOT11_BSSID_LIST;

        typedef struct _WLAN_CONNECTION_PARAMETERS 
        {
          WLAN_CONNECTION_MODE wlanConnectionMode;
          LPCWSTR              strProfile;
          PDOT11_SSID          pDot11Ssid;
          PDOT11_BSSID_LIST    pDesiredBssidList;
          DOT11_BSS_TYPE       dot11BssType;
          DWORD                dwFlags;
        } WLAN_CONNECTION_PARAMETERS, *PWLAN_CONNECTION_PARAMETERS;

        typedef struct _WLAN_NOTIFICATION_DATA {
          DWORD NotificationSource;
          DWORD NotificationCode;
          GUID  InterfaceGuid;
          DWORD dwDataSize;
          PVOID pData;
        } WLAN_NOTIFICATION_DATA, *PWLAN_NOTIFICATION_DATA;

        typedef struct _WLAN_CONNECTION_NOTIFICATION_DATA {
          WLAN_CONNECTION_MODE wlanConnectionMode;
          WCHAR                strProfileName[WLAN_MAX_NAME_LENGTH];
          DOT11_SSID           dot11Ssid;
          DOT11_BSS_TYPE       dot11BssType;
          BOOL                 bSecurityEnabled;
          WLAN_REASON_CODE     wlanReasonCode;
          DWORD                dwFlags;
          WCHAR                strProfileXml[1];
        } WLAN_CONNECTION_NOTIFICATION_DATA, *PWLAN_CONNECTION_NOTIFICATION_DATA;

        typedef struct _WLAN_MSM_NOTIFICATION_DATA {
          WLAN_CONNECTION_MODE wlanConnectionMode;
          WCHAR                strProfileName[WLAN_MAX_NAME_LENGTH];
          DOT11_SSID           dot11Ssid;
          DOT11_BSS_TYPE       dot11BssType;
          DOT11_MAC_ADDRESS    dot11MacAddr;
          BOOL                 bSecurityEnabled;
          BOOL                 bFirstPeer;
          BOOL                 bLastPeer;
          WLAN_REASON_CODE     wlanReasonCode;
        } WLAN_MSM_NOTIFICATION_DATA, *PWLAN_MSM_NOTIFICATION_DATA;

        typedef enum _WLAN_NOTIFICATION_MSM {
          wlan_notification_msm_start                           = 0,
          wlan_notification_msm_associating,
          wlan_notification_msm_associated,
          wlan_notification_msm_authenticating,
          wlan_notification_msm_connected,
          wlan_notification_msm_roaming_start,
          wlan_notification_msm_roaming_end,
          wlan_notification_msm_radio_state_change,
          wlan_notification_msm_signal_quality_change,
          wlan_notification_msm_disassociating,
          wlan_notification_msm_disconnected,
          wlan_notification_msm_peer_join,
          wlan_notification_msm_peer_leave,
          wlan_notification_msm_adapter_removal,
          wlan_notification_msm_adapter_operation_mode_change,
          wlan_notification_msm_end 
        } WLAN_NOTIFICATION_MSM, *PWLAN_NOTIFICATION_MSM;

        typedef enum _WLAN_NOTIFICATION_ACM {
          wlan_notification_acm_start                        = 0,
          wlan_notification_acm_autoconf_enabled,
          wlan_notification_acm_autoconf_disabled,
          wlan_notification_acm_background_scan_enabled,
          wlan_notification_acm_background_scan_disabled,
          wlan_notification_acm_bss_type_change,
          wlan_notification_acm_power_setting_change,
          wlan_notification_acm_scan_complete,
          wlan_notification_acm_scan_fail,
          wlan_notification_acm_connection_start,
          wlan_notification_acm_connection_complete,
          wlan_notification_acm_connection_attempt_fail,
          wlan_notification_acm_filter_list_change,
          wlan_notification_acm_interface_arrival,
          wlan_notification_acm_interface_removal,
          wlan_notification_acm_profile_change,
          wlan_notification_acm_profile_name_change,
          wlan_notification_acm_profiles_exhausted,
          wlan_notification_acm_network_not_available,
          wlan_notification_acm_network_available,
          wlan_notification_acm_disconnecting,
          wlan_notification_acm_disconnected,
          wlan_notification_acm_adhoc_network_state_change,
          wlan_notification_acm_profile_unblocked,
          wlan_notification_acm_screen_power_change,
          wlan_notification_acm_end 
        } WLAN_NOTIFICATION_ACM, *PWLAN_NOTIFICATION_ACM;

        #define L2_NOTIFICATION_SOURCE_NONE                   0
        #define L2_NOTIFICATION_SOURCE_DOT3_AUTO_CONFIG       0X00000001
        #define L2_NOTIFICATION_SOURCE_SECURITY              0X00000002
        #define L2_NOTIFICATION_SOURCE_ONEX                   0X00000004    
        #define L2_NOTIFICATION_SOURCE_WLAN_ACM          0X00000008
        #define L2_NOTIFICATION_SOURCE_WLAN_MSM          0X00000010
        #define L2_NOTIFICATION_SOURCE_WLAN_SECURITY     0X00000020
        #define L2_NOTIFICATION_SOURCE_WLAN_IHV          0X00000040
        #define L2_NOTIFICATION_SOURCE_WLAN_HNWK         0X00000080