Roman
Roman

Reputation: 1711

WlanConnect from wlanapi.dll in Windows XP fails

I am creating a program which will be able to connect automatically to a wireless network. For doing that, I am using a library called ManagedWifi, which uses the library "wlanapi.dll". When I try to use the code on Windows Vista, everything is fine, but when I use it on Windows XP it fails. I have checked that it has Service Pack 3 installed, and "wlanapi.dll" is located in Windows/system32. The problem is when ManagedWifi calls this method:

[DllImport("wlanapi.dll")]
    public static extern int WlanConnect(
        [In] IntPtr clientHandle,
        [In, MarshalAs(UnmanagedType.LPStruct)] Guid interfaceGuid,
        [In] ref WlanConnectionParameters connectionParameters,
        IntPtr pReserved);

It throws an error System.ComponentModel.Win32Exception: Element not found. But, if the library is correctly located in system32, why does it throw this error? And why only in Windows XP and not in Vista?

Thank you very much to everyone

EDIT: I have checked boith file versions, Vista and XP, and I've seen they are different (XP: 5.1, Vista: 6.0) but I have copied Vista's version to XP and I still have the same problem

Upvotes: 1

Views: 1076

Answers (2)

Abhimanyu Singh
Abhimanyu Singh

Reputation: 1

Using :

[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
    ); 

You have to create the profile first, Element not found says that the profile which you are trying to connect is not available

Upvotes: 0

Roman
Roman

Reputation: 1711

Solved

The problem is that Windows XP, when the network is an adhoc network, adds the "-adhoc" sufix to the name. When I was trying to connect to it, it didn't find the "xxx" network

Upvotes: 1

Related Questions