N
Nelson Guerrero
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.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
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.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