I'm trying to connect to a wifi-network using bssid and have gone through all links available (including codeplex for managedwifi). My code is returning the following error:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at WifiExample.Program.WlanConnect(IntPtr clientHandle, Guid& interfaceGuid,
WlanConnectionParameters& connectionParameters, IntPtr pReserved)
sometimes it throws a SEHException too.
Here is the code snippet:
try
{
WlanConnect(clientHandle, ref guidd, ref cp, IntPtr.Zero);
} catch(AccessViolationException e) {
Console.WriteLine();
Console.WriteLine(e.GetBaseException());
}
This is the function it calls. Its declared in the same file where i am calling it from.
[DllImport("wlanapi.dll")]
public static extern int WlanConnect(
[In] IntPtr clientHandle,
[In] ref System.Guid interfaceGuid,
[In] ref Wlan.WlanConnectionParameters connectionParameters,
IntPtr pReserved);
My code is based on this.
How can I solve this? Any help would be great!