DWORD   GetIpNetTable(   
      PMIB_IPNETTABLE   pIpNetTable,       //   buffer   for   mapping   table   
      PULONG   pdwSize,                   //   size   of   buffer   
      BOOL   bOrder                      //   sort   by   IP   address   
  );  

解决方案 »

  1.   

    extern uint GetIpNetTable(  
          out MIB_IPNETTABLE  pIpNetTable,      //  buffer  for  mapping  table  
          out uint  pdwSize,                  //  size  of  buffer  
          bool bOrder                      //  sort  by  IP  address  
      );  另外你要自己补全MIB_IPNETTABLE的声明.
      

  2.   

    ChrisAK,
    MIB_IPNETTABLE 在C#中没有这个类型啊?这个函数在System32下面的IPHLPAPI.dll中。我应该怎么找这个MIB_IPNETTABLE的声明啊?
      

  3.   


    typedef struct _MIB_IPNETTABLE {
      DWORD dwNumEntries; 
      MIB_IPNETROW table[ANY_SIZE]; 
    } MIB_IPNETTABLE, *PMIB_IPNETTABLE;这是在MSDN中找到的结构定义。那个方法导入的时候前面要加“DllImport”:
    [DllImport ("IPHLPAPI.dll")]
      

  4.   

    如果这样的话,在C#中声明这个函数不是很麻烦吗?MIB_IPNETROW 在C#中也没有,也要参照C++的Code,再自己struct一个MIB_IPNETROW。
     [DllImport("IPHLPAPI.dll")]
     extern uint GetIpNetTable(out MIB_IPNETTABLE pIpNetTable, out uint pdwSize,bool bOrder); 
    我只声明了这些,还差一些数据类型的定义,这些怎么办?
      

  5.   

    [DllImport("iphlpapi.dll", EntryPoint="GetIpNetTable")]
    static extern int GetIpNetTable(IntPtr pIpNetTable, ref int pdwSize, bool bOrder);
      

  6.   


    namespace test
    {
        class test
        {
          [DllImport("IPHLPAPI.dll")]
          extern uint GetIpNetTable(out MIB_IPNETTABLE pIpNetTable, out uint pdwSize,bool bOrder); 
        }
    }
    大家能不能帮我补全,我刚接触C#调用API,一点也不清楚。
      

  7.   

    http://topic.csdn.net/t/20061127/01/5186869.html自己找到了参考资料。好多不懂的内容啊!!
      

  8.   

    刚注意到这个API用到的结构是个变长体...
    变长体处理起来会比较麻烦.改用指针会简单很多.
    这里给个用指针遍历表的例子:using System;
    using System.Net;
    using System.Net.Sockets;
    using System.Runtime.InteropServices;struct MIB_IPNETROW
    {
        public uint dwIndex;
        public uint dwPhysAddrLen;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
        public byte[] bPhysAddr;//[];  
        public uint dwAddr;
        public uint dwType;
    }
    struct MIB_IPNETTABLE
    {
        public int dwNumEntries;
        public MIB_IPNETROW table;
    }unsafe class program
    {
        [DllImport("IPHLPAPI.dll")]
        static extern uint GetIpNetTable(void* pIpNetTable, out int pdwSize, bool bOrder);
        static void Main()
        {
            int bufSize;        GetIpNetTable(null, out bufSize, false);
            byte* pbuf = stackalloc byte[bufSize];
            GetIpNetTable(pbuf, out bufSize, false);
            //获取行数
            int numEntries = *(int*)pbuf;
            int size = Marshal.SizeOf(typeof(MIB_IPNETROW));
            //移动指针至第一行
            pbuf = (byte*)(((int*)pbuf) + 1);        //遍历表输出行
            for (int i = 0; i < numEntries; ++i,pbuf += size)
            {
                MIB_IPNETROW row = (MIB_IPNETROW)Marshal.PtrToStructure((IntPtr)pbuf, typeof(MIB_IPNETROW));
                IPAddress ip = new IPAddress(row.dwAddr);
                Console.Write("{0}=>", ip);
                if (row.dwPhysAddrLen == 0)
                {
                    Console.Write("N/A");
                }
                else
                {
                    int j;
                    for (j = 0; j < row.dwPhysAddrLen - 1; ++j)
                    {
                        Console.Write("{0:X2}-", row.bPhysAddr[j]);
                    }
                    Console.Write("{0:X2}", row.bPhysAddr[j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine("{0} rows displayed", numEntries);
        }
    }