2

I am facing an error when calling the WlanConnect function from the WindowsAPI, I am getting ERROR_INVALID_PARAMETER, even though my code doesn't get in any of the conditions specified in http://msdn.microsoft.com/en-us/library/windows/desktop/ms706613(v=vs.85).aspx to get this error.

Here it is my Connect() method

public void Connect(string profile, Dot11SsidStruct ssidStruct)
{
    DebugConsole.WriteLine("profile: " + profile);
    DebugConsole.WriteLine("ssid: " + Encoding.UTF8.GetString(ssidStruct.SSID));

    Debug.Assert(profile != string.Empty);


    var parameters = new WlanConnectionParametersStruct();

    var pSsid = Marshal.AllocHGlobal(Marshal.SizeOf(ssidStruct));
    try
    {
        parameters.strPofile = profile;
        parameters.WlanConnectionMode = WlanConnectionMode.Profile;
        parameters.Dot11BssType = Dot11BssType.Independent;
        parameters.dwFlags = WlanConnectionFlags.AdhocJoinOnly;

        Marshal.StructureToPtr(ssidStruct, pSsid, false);

        parameters.pDot11Ssid = pSsid;

        var result = PInvoke.WlanConnect(_handle, InterfaceInfo.InterfaceGuid, ref parameters, IntPtr.Zero);

        if (result != 0)
            throw new Win32Exception(result);
     }
     finally
     {
         Marshal.FreeHGlobal(pSsid);
     }
}

I am not sure what am I doing wrong, if anyone could guide my on any approach to solve this problem it would be great.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bruno Klein
  • 3,217
  • 5
  • 29
  • 39
  • I think there could be something wrong with the dllimport. Can you try this wrapper http://www.codeproject.com/script/Content/ViewAssociatedFile.aspx?rzp=%2FKB%2FIP%2FWIFI_Native_API%2F%2FPRJ_WIFI_CODEPROJECT.COM.zip&zep=ManagedWifi%2FWlanAPIWrap.cs&obid=72105&obtid=2&ovid=9.... Here is the code project article for this link http://www.codeproject.com/Articles/72105/Manage-WiFi-with-Native-API-WIFI-on-Windows-XP-SP – Suresh Kumar Veluswamy Mar 19 '14 at 08:58

0 Answers0