473,325 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

wlanapi.dll c#

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
Apr 27 '07 #1
2 7646
Nelson,
>public class WLAN_PROFILE_INFO_LIST
{
public int dwNumberOfItems;
public int dwIndex;
[MarshalAs(UnmanagedType.ByValArray)]
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(
[In] IntPtr hClientHandle,
[In] Guid pInterfaceGuid,
[In] string pReserved,
[Out]
[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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 27 '07 #2
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
Mattias Sjögren wrote:
Nelson,
>public class WLAN_PROFILE_INFO_LIST
{
public int dwNumberOfItems;
public int dwIndex;
[MarshalAs(UnmanagedType.ByValArray)]
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(
[In] IntPtr hClientHandle,
[In] Guid pInterfaceGuid,
[In] string pReserved,
[Out]
[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
Apr 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: =?Utf-8?B?TU1B?= | last post by:
Hi All, Need help with writing a wrapper around wlanapi.dll. I am able to successfully call WlanOpenHandle and get a handler back; but when I call WlanEnumInterfaces or WlanGetAvailableNetworkList...
1
by: ghstrdr113 | last post by:
I get an error message that is as follows: bcmwtry.exe- Unable to locate Component This application has failed to start because Wlanapi.dll was not found. Re-installing the application may fix...
1
by: Nighthawk | last post by:
I am trying to use NativeWifi. I tried putting "Using NativeWifi" in my C# code but it throws error right there. I think I will need to add reference to my application. I don't know which dll i...
5
by: Toby Webb | last post by:
How can I convert the following code (from MSDN) to work in VB.NET (the opcodes are raising errors): Public Enum WLAN_INTF_OPCODE wlan_intf_opcode_autoconf_start = 0x000000000...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.