none
wlanapi.dll WlanDisconnect function Question RRS feed

  • Question

  • Ok, after searching through a number of sites and how to's I put together some code for this.  I am using the native wifi API for windows XP sp2.  Unfortunately it doesn't work and now I am stumped again.  Here is what I have so far.

    [DllImport("wlanapi.dll")] //Import dll for WlanDisconnect function  
    static extern IntPtr WlanDisconnect([In] IntPtr hClientHandle, [In, MarshalAs(UnmanagedType.LPStruct)] Guid pInterfaceGuid, [In, Out] IntPtr pReserved);  
     
     
    [DllImport("wlanapi.dll")] //Import dll for WlanOpenHandle function   
    static extern int WlanOpenHandle([In] UInt32 dwClientVersion, [In, Out] IntPtr pReserved, [Out] out UInt32 pdwNegotiatedHandle, [Out] out IntPtr phClientHandle);  
     
     
    Guid WirelessGuid = new Guid(getGUID());  
     
    uint pdwNegHandle;  
     
    IntPtr phChandle;  
     
    IntPtr Pvoid = new IntPtr();  
     
    WlanOpenHandle((UInt32)1, Pvoid, out pdwNegHandle, out phChandle);  
     
    WlanDisconnect(phChandle, WirelessGuid, Pvoid);  
     


    getGUID() gets the GUID, as a string, of the interface I want to disconnect.

    I checked the return values for WlanDisconnect and WlanOpenHandle and I get 1062 and 87 respectively.  I am not really sure what they are supposed to be.  Also, the values for phChandle and pdwNegHandle are both 0, which I am assuming means I am not getting a good return from the WlanOpenHandle call.  If anyone knows where I am going wrong here let me know. 


    Thanks,

    Joe
    Thursday, March 26, 2009 2:51 PM

Answers

  • Using the Windows SDK's WinError.h file, 1062 is "The service has not been started" and 87 is "The parameter is incorrect".  Those are the strings you'll see when you throw a Win32Exception with those values.

    You'll need to declare the Guid argument as ref, omit [MarshalAs].  Use IntPtr.Zero instead of Pvoid.  I assume you reversed the error codes in your post.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Wednesday, April 1, 2009 9:40 AM
    Thursday, March 26, 2009 10:19 PM
    Moderator

All replies

  • Using the Windows SDK's WinError.h file, 1062 is "The service has not been started" and 87 is "The parameter is incorrect".  Those are the strings you'll see when you throw a Win32Exception with those values.

    You'll need to declare the Guid argument as ref, omit [MarshalAs].  Use IntPtr.Zero instead of Pvoid.  I assume you reversed the error codes in your post.

    Hans Passant.
    • Marked as answer by Zhi-Xin Ye Wednesday, April 1, 2009 9:40 AM
    Thursday, March 26, 2009 10:19 PM
    Moderator
  • Ok, so I changed a the things you said to change and it still didn't work.  Then I decided to look up why it was giving the error service not started.  What I found is that this specific api works only with the WZC service which I should have realized before I started using it considering its the windows Native wifi api.  The reason it didn't work is because I am using Proset to manage wifi connections, but when I enabled wzc to control wifi it works just fine. 

    Now my next challenge is trying to find a way around that.  I was thinking something along the lines of Ndis but I don't have the slightes idea where to start with that.

    Thanks,

    Joe
    Friday, March 27, 2009 1:53 PM
  • You're well out of the scope of this forum now.  You probably need some kind of Intel support forum or networking newsgroup.
    Hans Passant.
    Friday, March 27, 2009 4:34 PM
    Moderator