0
即時通訊嘗試從Windows 10下的C#桌面應用程序互操作WlanGetNetworkBssList。有一些問題來正確檢索WLAN_BSS_LIST。不知道問題出在哪裏,我得到的名單是錯誤的。第一項似乎是正確的,但其他所有的都是正確的。我希望有一個人可以幫助我。WlanGetNetworkBssList與C#在Windows 10
這些是我正在使用的結構。我相信問題是一個錯誤的結構定義。
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct WLAN_BSS_LIST
{
internal Int32 dwTotalSize;
internal Int32 dwNumberOfItems;
internal WLAN_BSS_ENTRY[] wlanBssEntries;
internal WLAN_BSS_LIST(IntPtr ppWlanBssList)
{
dwTotalSize = (Int32)Marshal.ReadInt32(ppWlanBssList);
dwNumberOfItems = (Int32)Marshal.ReadInt32(ppWlanBssList + 4);
wlanBssEntries = new WLAN_BSS_ENTRY[dwNumberOfItems];
int WLAN_BSS_ENTRY_SIZE = Marshal.SizeOf(typeof(WLAN_BSS_ENTRY));
for (int i = 0; i < dwNumberOfItems; i++)
{
IntPtr pItemList = new IntPtr(ppWlanBssList.ToInt32() + i * Marshal.SizeOf(typeof(WLAN_BSS_ENTRY)) + 8);
wlanBssEntries[i] = (WLAN_BSS_ENTRY)Marshal.PtrToStructure(pItemList, typeof(WLAN_BSS_ENTRY));
}
}
}
public struct WLAN_BSS_ENTRY
{
public DOT11_SSID dot11Ssid;
public ulong uPhyId;
public DOT11_MAC_ADDRESS dot11Bssid;
public DOT11_BSS_TYPE dot11BssType;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public DOT11_PHY_TYPE[] dot11BssPhyType;
public long lRssi;
public ulong uLinkQuality;
public bool bInRegDomain;
public ushort usBeaconPeriod;
public ulong ullTimestamp;
public ulong ullHostTimestamp;
public ushort usCapabilityInformation;
public ulong ulChCenterFrequency;
public WLAN_RATE_SET wlanRateSet;
public ulong ulIeOffset;
public ulong ulIeSize;
}
public struct DOT11_SSID
{
public uint uSSIDLength;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string ucSSID;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct DOT11_MAC_ADDRESS
{
public byte one;
public byte two;
public byte three;
public byte four;
public byte five;
public byte six;
}
public enum DOT11_BSS_TYPE
{
dot11_BSS_type_infrastructure = 1,
dot11_BSS_type_independent = 2,
dot11_BSS_type_any = 3,
}
public enum DOT11_PHY_TYPE
{
dot11_phy_type_unknown,
dot11_phy_type_any,
dot11_phy_type_fhss,
dot11_phy_type_dsss,
dot11_phy_type_irbaseband,
dot11_phy_type_ofdm,
dot11_phy_type_hrdsss,
dot11_phy_type_erp,
dot11_phy_type_ht,
dot11_phy_type_IHV_start,
dot11_phy_type_IHV_end,
}
public struct WLAN_RATE_SET
{
public ulong uRateSetLength;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 126)]
public ushort[] usRateSet;
}
爲什麼將'dot11BssPhyType'字段('WLAN_BSS_ENTRY')的類型設置爲數組?另外,當計算第i個BSS條目的地址時,你可以在指針上使用'ToInt32()'(我認爲),所以如果你的應用程序是64位的,你可能會丟失一些(32)位。 –