C#wlanapi.dll接收信号强度时出现问题

C#wlanapi.dll接收信号强度时出现问题,c#,.net,interop,wlanapi,C#,.net,Interop,Wlanapi,我目前正在尝试使用wlanapi.dll WlanQueryInterface调用从无线接入点检索信号强度 这是我的api声明 [DllImport("wlanapi.dll", SetLastError = true)] private static extern UInt32 WlanQueryInterface(IntPtr hClientHandle, ref Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, IntPtr pReserv

我目前正在尝试使用wlanapi.dll WlanQueryInterface调用从无线接入点检索信号强度

这是我的api声明

    [DllImport("wlanapi.dll", SetLastError = true)]
private static extern UInt32 WlanQueryInterface(IntPtr hClientHandle, ref Guid pInterfaceGuid, WLAN_INTF_OPCODE OpCode, IntPtr pReserved, out Int32 pdwDataSize, ref IntPtr ppData, IntPtr pWlanOpCodeValueType);
问题是,当我查看WLAN_ASSOCIATION_ATTRIBUTES结构中的WLANSIGNALSTRENGHT条目时,它被设置为5400。Microsoft API文档说明它应该是一个介于0到100之间的值

以下是我的结构声明:

    /// <summary>
/// Structure contains association attributes for a connection.
/// </summary>
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
private struct WLAN_ASSOCIATION_ATTRIBUTES
{
    /// <summary>
    /// A DOT11_SSID structure that contains the SSID of the association.
    /// </summary>
    public DOT11_SSID dot11Ssid;
    /// <summary>
    /// A DOT11_BSS_TYPE value that specifies whether the network is infrastructure or ad hoc.
    /// </summary>
    public DOT11_BSS_TYPE dot11BssType;
    /// <summary>
    /// A DOT11_MAC_ADDRESS that contains the BSSID of the association.
    /// </summary>
    public DOT11_MAC_ADDRESS dot11Bssid;
    /// <summary>
    /// A DOT11_PHY_TYPE value that indicates the physical type of the association
    /// </summary>
    public DOT11_PHY_TYPE dot11PhyType;
    /// <summary>
    /// The position of the DOT11_PHY_TYPE value in the structure containing the list of PHY types.
    /// </summary>
    public ulong uDot11PhyIndex;
    /// <summary>
    /// A percentage value that represents the signal quality of the network.
    /// </summary>
    public Int32 wlanSignalQuality;
    /// <summary>
    /// Contains the receiving rate of the association.
    /// </summary>
    public ulong ulRxRate;
    /// <summary>
    /// Contains the transmission rate of the association.
    /// </summary>
    public ulong ulTxRate;
}

有人知道我做错了什么吗?提前谢谢

我终于把它修好了。我必须将WLAN_ASSOCIATION_属性的LayoutKind设置为Explicit,并将字符集设置为Unicode

    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
private struct WLAN_ASSOCIATION_ATTRIBUTES
{
    /// <summary>
    /// A DOT11_SSID structure that contains the SSID of the association.
    /// </summary>
    [FieldOffset(0)]
    public DOT11_SSID dot11Ssid;
    /// <summary>
    /// A DOT11_BSS_TYPE value that specifies whether the network is infrastructure or ad hoc.
    /// </summary>
    [FieldOffset(0x24)]
    public DOT11_BSS_TYPE dot11BssType;
    /// <summary>
    /// A DOT11_MAC_ADDRESS that contains the BSSID of the association.
    /// </summary>
    [FieldOffset(40)]
    public DOT11_MAC_ADDRESS dot11Bssid;
    /// <summary>
    /// A DOT11_PHY_TYPE value that indicates the physical type of the association
    /// </summary>
    [FieldOffset(0x30)]
    public DOT11_PHY_TYPE dot11PhyType;
    /// <summary>
    /// The position of the DOT11_PHY_TYPE value in the structure containing the list of PHY types.
    /// </summary>
    [FieldOffset(0x34)]
    public ulong uDot11PhyIndex;
    /// <summary>
    /// A percentage value that represents the signal quality of the network.
    /// </summary>
    [FieldOffset(0x38)]
    public Int32 wlanSignalQuality;
    /// <summary>
    /// Contains the receiving rate of the association.
    /// </summary>
    [FieldOffset(60)]
    public ulong ulRxRate;
    /// <summary>
    /// Contains the transmission rate of the association.
    /// </summary>
    [FieldOffset(0x40)]
    public ulong ulTxRate;
}
[StructLayout(LayoutKind.Explicit,CharSet=CharSet.Unicode)]
私有结构WLAN\u关联\u属性
{
/// 
///包含关联的SSID的Dot11U SSID结构。
/// 
[字段偏移量(0)]
公共DOT11_SSID dot11Ssid;
/// 
///DOT11_BSS_类型值,用于指定网络是基础结构还是临时网络。
/// 
[字段偏移量(0x24)]
公共DOT11_BSS_类型dot11BssType;
/// 
///包含关联的BSSID的DOT11\u MAC\u地址。
/// 
[现场偏移(40)]
公共DOT11\u MAC\u地址dot11Bssid;
/// 
///指示关联的物理类型的DOT11物理类型值
/// 
[字段偏移量(0x30)]
公共DOT11物理类型dot11PhyType;
/// 
///DOT11_PHY_TYPE值在包含PHY类型列表的结构中的位置。
/// 
[字段偏移量(0x34)]
公共ulong Udot11指数;
/// 
///表示网络信号质量的百分比值。
/// 
[字段偏移量(0x38)]
公共Int32无线信号质量;
/// 
///包含关联的接收速率。
/// 
[现场偏移(60)]
公共乌龙乌尔克斯拉特;
/// 
///包含关联的传输速率。
/// 
[字段偏移量(0x40)]
公共ulong ulTxRate;
}

我认为只要冷却时间允许,你应该接受这个答案,除非有管理员过来。
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
private struct WLAN_ASSOCIATION_ATTRIBUTES
{
    /// <summary>
    /// A DOT11_SSID structure that contains the SSID of the association.
    /// </summary>
    [FieldOffset(0)]
    public DOT11_SSID dot11Ssid;
    /// <summary>
    /// A DOT11_BSS_TYPE value that specifies whether the network is infrastructure or ad hoc.
    /// </summary>
    [FieldOffset(0x24)]
    public DOT11_BSS_TYPE dot11BssType;
    /// <summary>
    /// A DOT11_MAC_ADDRESS that contains the BSSID of the association.
    /// </summary>
    [FieldOffset(40)]
    public DOT11_MAC_ADDRESS dot11Bssid;
    /// <summary>
    /// A DOT11_PHY_TYPE value that indicates the physical type of the association
    /// </summary>
    [FieldOffset(0x30)]
    public DOT11_PHY_TYPE dot11PhyType;
    /// <summary>
    /// The position of the DOT11_PHY_TYPE value in the structure containing the list of PHY types.
    /// </summary>
    [FieldOffset(0x34)]
    public ulong uDot11PhyIndex;
    /// <summary>
    /// A percentage value that represents the signal quality of the network.
    /// </summary>
    [FieldOffset(0x38)]
    public Int32 wlanSignalQuality;
    /// <summary>
    /// Contains the receiving rate of the association.
    /// </summary>
    [FieldOffset(60)]
    public ulong ulRxRate;
    /// <summary>
    /// Contains the transmission rate of the association.
    /// </summary>
    [FieldOffset(0x40)]
    public ulong ulTxRate;
}