C# 在Windows CE 6.0 CF.NET 2.0上删除ARP条目

C# 在Windows CE 6.0 CF.NET 2.0上删除ARP条目,c#,dll,pinvoke,compact-framework,arp,C#,Dll,Pinvoke,Compact Framework,Arp,我必须解决的任务是向目标设备发送ARP请求 因此,我开始在WindowsCE6.0的C#-CompactFramework.NET2.0中p/调用SendARP [DllImport("iphlpapi.dll")] private static extern int SendARP(uint destIp, uint srcIp, [Out] byte[] pMacAddr, ref int phyAddrLen); 在识别出本地ARP缓存用于已存在的请求IP条目后,我想手动删除该条目 因此

我必须解决的任务是向目标设备发送ARP请求

因此,我开始在WindowsCE6.0的C#-CompactFramework.NET2.0中p/调用SendARP

[DllImport("iphlpapi.dll")]
private static extern int SendARP(uint destIp, uint srcIp, [Out] byte[] pMacAddr, ref int phyAddrLen);
在识别出本地ARP缓存用于已存在的请求IP条目后,我想手动删除该条目

因此,我开始使用下面的代码从

我最终成功地加载了我的MIB_IPNETROW,但是当我调用

[DllImport("iphlpapi.dll")]
private static extern int DeleteIpNetEntry(MIB_IPNETROW pArpEntry);
我得到一个错误\u无效\u参数异常(代码87)

这是我的结构:(我测试了它的两个版本)

最后但并非最不重要的是,我的职能:

    private static void DeleteArpCache(string dstAddress, bool flush)
    {
        if (!string.IsNullOrEmpty(dstAddress))
        {
            IPAddress ipAddress = IPAddress.Parse(dstAddress);
            byte[] destination = ipAddress.GetAddressBytes();

            Log.DebugFormat("Try to get MIB_IPNETROW for IP [{0}]", dstAddress);
            MIB_IPNETROW? rowValue = GetRowByIpNetTable(destination);
            if (rowValue != null)
            {
                MIB_IPNETROW row = (MIB_IPNETROW) rowValue;

                if (flush)
                {
                    Log.DebugFormat("Try to delete ARP entries for Adapter Index {0}", row.dwIndex);
                    int result = FlushIpNetTable(row.dwIndex);
                    if (result == 0)
                    {
                        Log.Info("Deleted ARP entries successfully");
                    }
                    else
                    {
                        Log.ErrorFormat("Delete ARP entries failed with Code {0} for destination [{1}]", result,
                            dstAddress);
                    }
                }
                else
                {
                    Log.DebugFormat("Try to delete single ARP entry for IP [{0}]", dstAddress);
                    int result = DeleteIpNetEntry(row);
                    if (result == 0)
                    {
                        Log.Info("Deleted ARP entry successfully");
                    }
                    else
                    {
                        Log.ErrorFormat("Delete ARP entry failed with Code {0} for destination [{1}]", result,
                            dstAddress);
                    }
                }
            }
        }
    }
FlushIpNetTable就像一个符咒! 那么,我在DeleteIpNetEntry的参数不匹配的原因是什么? 有人有过类似的问题吗


亲切的问候

确实如此!约瑟夫是对的,这个参数是ref

[DllImport("iphlpapi.dll")]
private static extern int DeleteIpNetEntry(ref MIB_IPNETROW pArpEntry);

非常感谢你

尝试使用指向结构的点使用DeleteIpNetEntry(使用ref关键字)。看见
[DllImport("iphlpapi.dll")]
private static extern int DeleteIpNetEntry(ref MIB_IPNETROW pArpEntry);