求仅具有引用指针的对象数组的总大小?
总而言之,我正在使用 Wlanapi,而且我对它相当陌生(一般来说是原生 api)。我在将结构从 C++ 转换为 C# 时遇到问题。现在我有:
Original:
typedef struct _WLAN_BSS_LIST {
DWORD dwTotalSize;
DWORD dwNumberOfItems;
WLAN_BSS_ENTRY wlanBssEntries[1];
} WLAN_BSS_LIST, *PWLAN_BSS_LIST;
Conversion:
[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 引用的数组的总大小:(
仅供参考,如果有人指出我,我会非常失望一个现有的库。
编辑以添加原始结构
So as an overview, I am working with the Wlanapi and I am fairly new to it (native apis in general). I am running into a problem converting a structure from c++ to c#. Right now I have:
Original:
typedef struct _WLAN_BSS_LIST {
DWORD dwTotalSize;
DWORD dwNumberOfItems;
WLAN_BSS_ENTRY wlanBssEntries[1];
} WLAN_BSS_LIST, *PWLAN_BSS_LIST;
Conversion:
[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));
}
}
}
I just don't know how to get the total size of the array referenced by ppBssList
:(
As an fyi, I will be extremely disappointed if someone points me to an existing library.
Edited to add original struct
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你的 twTotalSize 是否反映了为 wlanBssEntries 中的条目分配的内存量,如果是这样,一个简单的计算就足够了,
否则,我建议你发布原始的本机数据结构,也许,有更好的从内存块编组它的替代方法。
I'm not sure if your twTotalSize reflects the amount of memory allocated for the entries in wlanBssEntries, if so, a simple calculation would be sufficient,
otherwise, I suggest that you post the original native data structure, maybe, there is a much better alternative for marshaling it from the memory block.
所以我明白了,我不知道我在想什么......
然后
So I figured it out, I dunno what I was thinking...
And