因此,作为概述,我正在使用 Wlanapi,而且我对它相当陌生(一般是原生 api)。我在将结构从 c++ 转换为 c# 时遇到问题。现在我有:
原来的:
typedef struct _WLAN_BSS_LIST {
DWORD dwTotalSize;
DWORD dwNumberOfItems;
WLAN_BSS_ENTRY wlanBssEntries[1];
} WLAN_BSS_LIST, *PWLAN_BSS_LIST;
转换:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct WLAN_BSS_LIST
{
internal uint dwTotalSize;
internal uint dwNumberOfItems;
internal WLAN_BSS_ENTRY[] wlanBssEntries;
internal WLAN_BSS_LIST(IntPtr ppBssList)
{
dwNumberOfItems = (uint)Marshal.ReadInt32(ppBssList);
//I need to set the value of dwTotalSize but I dunno how
wlanBssEntries = new WLAN_BSS_ENTRY[dwNumberOfItems];
for (int i = 0; i < dwNumberOfItems; i++)
{
IntPtr pWlanBssEntry = new IntPtr(ppBssList.ToInt32() + i *
Marshal.SizeOf(typeof(WLAN_BSS_ENTRY)) + 8);
wlanBssEntries[i] = (WLAN_BSS_ENTRY)Marshal.
PtrToStructure(pWlanBssEntry,
typeof(WLAN_BSS_ENTRY));
}
}
}
我只是不知道如何获得所引用的数组的总大小ppBssList
:(
作为一个仅供参考,如果有人将我指向现有的图书馆,我会非常失望。
编辑添加原始结构