我正在创建一个程序,它将能够自动连接到无线网络。为此,我使用一个名为ManagedWifi的库,它使用库"wlanapi.dll“。当我尝试在Windows上使用代码时,一切都很好,但是当我在Windows上使用它时,它会失败。我已经检查过它是否安装了Service 3,"wlanapi.dll“位于Windows/system32 32中。问题是当ManagedWifi调用此方法时:
[DllImport("wlanapi.dll")]
public static extern int WlanConnect(
[In] IntPtr clientHandle,
[In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
[In] ref WlanConnectionParameters connectionParameters,
IntPtr pReserved);它抛出一个错误System.ComponentModel.Win32Exception:元素,该元素未找到。但是,如果库正确地位于system32中,为什么要抛出这个错误?为什么只在Windows中而不在Vista中?
非常感谢大家
编辑:我已经检查了boith文件版本,Vista和XP,并且我看到它们是不同的( XP : 5.1,Vista: 6.0),但是我已经将的版本复制到XP中,我仍然有相同的问题
发布于 2011-11-30 08:56:22
解决了
问题是,当网络是adhoc网络时,Windows会在名称中添加"-adhoc“sufix。当我试图连接到它时,它没有找到"xxx“网络
发布于 2021-09-14 08:00:10
使用:
[DllImport("wlanapi.dll")]
internal static extern int WlanSetProfile(
[In] IntPtr hClientHandle,
[In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
[In] WlanProfileFlags dwFlags,
[In, MarshalAs(UnmanagedType.LPWStr)] string strProfileXml,
[In, MarshalAs(UnmanagedType.LPWStr)] string strAllUserProfileSecurity,
[In] bool bOverwrite,
[In, Out] IntPtr pReserved,
[Out] out WlanReasonCode dwReasonCode
); 您必须首先创建配置文件,元素not表示您要连接的配置文件不可用。
https://stackoverflow.com/questions/8308345
复制相似问题