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.

4

0 回答 0