使用托管WiFi的问题(NativeWiFi API)

我正在尝试使用Native WiFi( https://managedwifi.codeplex.com/ )创建并连接到WLAN配置文件。 我能够查看所有网络BSS列表及其参数。 但是,当我尝试创建/覆盖WLAN配置文件时,我收到以下提到的错误消息(错误#1):

ManagedWifi.dll中发生了未处理的“System.ComponentModel.Win32Exception”类型exception。

附加信息:网络连接配置文件已损坏

但是,当我通常从Windows 7控制面板的“网络和共享中心”创建配置文件,然后尝试使用ManagedWiFi进行连接时,我收到另一条错误消息(错误#2):

mscorlib.dll中发生了未处理的“System.ArgumentException”类型exception

附加信息:类型’NativeWifi.Wlan + WlanReasonCode’不能作为非托管结构封送; 无法计算有意义的大小或偏移量。

我注意到即使我尝试从“网络和共享中心”连接/断开WLAN配置文件,并且Windows应用程序在后台运行,也会发生此错误。

以下是我使用的示例代码:

Dim profileName As String = GlobalVariables.ssidname ' Provides the selected SSID name from the Network BSS List Dim hexval As String = StringToHex(GlobalVariables.ssidname) ' Function to get the hexadecimal value for a provided string Dim key As String = TextBox1.Text ' Security key from the textbook provided Dim profileXml As String = String.Format("{0}{1}{0}ESSopenWEPfalsenetworkKeyfalse{2}0", 'GlobalVariables.ssidname, hexval, TextBox1.Text) wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, True) 'Error#1 occurs here wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName) 'Error#2 occurs here 

从论坛“ 类型Native Wifi.Wlan + WlanReasonCode不能编组错误 ”,问题(错误#2)似乎在WlanAPI.cs内,其中有一行代码检查返回代码的大小。 这是一行:

 int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanReasonCode)); if (notifyData.dataSize >= expectedSize) { Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr); if (wlanIface != null) wlanIface.OnWlanReason(notifyData, reasonCode); } 

将上面的代码更改为以下似乎可以解决问题。

 //int expectedSize = Marshal.SizeOf(typeof(Wlan.WlanReasonCode)); if (notifyData.dataSize >= 0) { Wlan.WlanReasonCode reasonCode = (Wlan.WlanReasonCode)Marshal.ReadInt32(notifyData.dataPtr); if (wlanIface != null) wlanIface.OnWlanReason(notifyData, reasonCode); } 

但是,我不确定如何将此修复程序添加到我的解决方案中。 我从NuGet包管理器安装了ManagedWiFi。 因此,不知道如何更改WlanApi.cs文件。 关于上述两个问题的任何帮助都非常感谢。

问题(错误#1)现在已解决。 profilexml文件格式对我来说是不同的。 这是我更改后的profilexml。

 Dim profileXml As String = String.Format("{0}{1}{0}ESSautoWPA2PSKAESfalsepassPhrasefalse{2}", GlobalVariables.ssidname, hexval, TextBox1.Text) 

当我从我的解决方案中卸载ManagedWiFi软件包并将整个ManagedWiFi项目添加到解决方案时,第二个问题(错误#2)也得到了解决。 然后我在SimpleWiFi或Type Native Wifi中提到了WlanApi.cs中的更改.Wlan + WlanReasonCode无法编组错误 。