Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / April 2007

Tip: Looking for answers? Try searching our database.

wlanapi.dll c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nelson Guerrero - 27 Apr 2007 21:41 GMT
Hi, I'm trying to obtain the profile list using the wlanapi.dll but I'm
receveing errors. The following code is what I've done so far. I took
the structures and functions definition from
http://msdn2.microsoft.com/en-us/library/ms706716.aspx

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WLAN_PROFILE_INFO
{
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
        public char[] strInterfaceDescription;
    public int dwFlags;
}

public class WLAN_PROFILE_INFO_LIST
{
    public int dwNumberOfItems;
        public int dwIndex;
        [MarshalAs(UnmanagedType.ByValArray)]
        public WLAN_PROFILE_INFO[] ProfileInfo;
}

[DllImport("wlanapi.dll", SetLastError = true)]
        private static extern int WlanGetProfileList(
            [In] IntPtr hClientHandle,
            [In] Guid pInterfaceGuid,
            [In] string pReserved,
            [Out]
[System.Runtime.InteropServices.MarshalAsAttribute(UnmanagedType.LPStruct)]
            out WLAN_PROFILE_INFO_LIST ppProfileList);

private void myfunction()
{
        int ierror;

            string pReservedGetAvailableNetworkList = null;
            ierror = WlanEnumInterfaces(phClientHandle,    
pReservedGetAvailableNetworkList, out this.wIIL);
            for (int i = 0; i < wIIL.dwNumberOfItems; i++)
            {
        WLAN_PROFILE_INFO_LIST wPIL=new                             WLAN_PROFILE_INFO_LIST();
                ierror = WlanGetProfileList(phClientHandle,
                wIIL.InterfaceInfo[i].InterfaceGuid,
                    pReservedGetAvailableNetworkList , out wPIL);
            }

}

When I call "myfunction()" I receive the following message:
PInvokeStackImbalance was detected
Message: A call to PInvoke function 'WlanapiWrapper::WlanGetProfileList'
has unbalanced the stack. This is likely because the managed PInvoke
signature does not match the unmanaged target signature. Check that the
calling convention and parameters of the PInvoke signature match the
target unmanaged signature.
I checked all the types, and I did it based on the functions that
already work like WlanOpenHandle and WlanEnumInterfaces, as you see both
 functions have the same parameters definition so  what I know is that
the message refers to the type that I defined on the declaration method,
I tried changing it and I received different errors, so, I'll appreciate
any help cause this problem is driving me crazy.

Thanks,
Nelson
Mattias Sjögren - 27 Apr 2007 22:19 GMT
Nelson,

>public class WLAN_PROFILE_INFO_LIST
>{
[quoted text clipped - 3 lines]
>         public WLAN_PROFILE_INFO[] ProfileInfo;
>}

You can't use ByValArray without also specifying an array size with
SizeConst. In other words, you can't use it for variable length
structs. Here's some guidance on how you can deal with that

http://dotnetinterop.com/faq/?q=VariableLengthStruct

>[DllImport("wlanapi.dll", SetLastError = true)]
>         private static extern int WlanGetProfileList(
[quoted text clipped - 4 lines]
>[System.Runtime.InteropServices.MarshalAsAttribute(UnmanagedType.LPStruct)]
>             out WLAN_PROFILE_INFO_LIST ppProfileList);

Should be

[DllImport("wlanapi.dll", SetLastError = true)]
        private static extern int WlanGetProfileList(
            [In] IntPtr hClientHandle,
            [In] ref Guid pInterfaceGuid,
            [In] string pReserved,
            out IntPtr ppProfileList);

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nelson Guerrero - 30 Apr 2007 21:31 GMT
Mattias, well, I dont know. Like I said, it works in the same way with
the other structures, so why this one needs to be changed? Anyway, I
change just the guid parameter and declared ref and it works. :) So, Its
a bit confusing.
Thanks

Nelson

> Nelson,
>
[quoted text clipped - 31 lines]
>
> Mattias

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.