![](/img/trans.png)
[英]Using the iphlpapi.dll in .Net to Add new IP Addresses on x64 machines
[英]using [DllImport(“iphlpapi.dll”)] in windows 7 64 bit
[DllImport("iphlpapi.dll")]
private static extern int GetTcpTable(IntPtr pTcpTable, ref int pdwSize, bool bOrder);
我正在使用此DLL並將該函數調用為GetTcpTable(IntPtr.Zero, ref iBytes, false)
它在Windows 7 32位操作系統中正常工作但不能在64位操作系統中工作。如何才能使它在Windows 7 64位操作系統中工作?
看起來問題與您的簽名有關:
private static extern int GetTcpTable(IntPtr pTcpTable, ref int pdwSize, bool bOrder);
查看文檔 ,它顯示以下內容:
public static extern int GetTcpTable(byte[] pTcpTable, out int pdwSize, bool bOrder);
您正在使用IntPtr,但它應該是一個將填充MIB_TCPTABLE結構的緩沖區。
我嘗試找到引用正確方法來實現所有這些的文章,但沒有找到很多。 令我感到震驚的是,pinvoke.net甚至沒有列出GetTcpTable,也沒有列出我上面提到的結構。
編輯:你可能想看看GetExtendedTcpTable()
我還發現在Vista中引入了一個GetTcpTable2() 。 它包含相同的簽名,所以也許只是看看調用它而不是讓它神奇地在x64上工作,因為你當前的調用應該適用於x86。 它可能不會100%開箱即用,但我很好奇它是否會讓你更遠或至少有不同的結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.