It looks like the problem is with your signature:
private static extern int GetTcpTable(IntPtr pTcpTable, ref int pdwSize, bool bOrder);
Looking at the documentation , the following is displayed instead:
public static extern int GetTcpTable(byte[] pTcpTable, out int pdwSize, bool bOrder);
You are using IntPtr, but it must be a buffer that will be filled with the MIB_TCPTABLE structure.
I tried to find articles, citing the correct way to implement all this, but did not find much. I am shocked that pinvoke.net does not even list GetTcpTable and the structure I mentioned above.
EDIT: You can take a look at GetExtendedTcpTable()
I also found that there is GetTcpTable2 () that was introduced in Vista. It contains the same signature, so maybe just see if it causes a call, and it makes it magically work on x64, since your current call supposedly works on x86. It may not work 100% right out of the box, but I'm curious if it takes you further or at least a different result.
source share