我一直在为 WFP(Windows 过滤平台)编写我的 c# 包装器,我使用 WinDivert 1.0.5,这个导入语法
[DllImportAttribute("WinDivert.dll", EntryPoint = "DivertRecv",SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
public static extern bool DivertRecv([InAttribute()] System.IntPtr handle,
[OutAttribute()] System.IntPtr pPacket,
[InAttribute()] uint packetLen,
[ OutAttribute()] System.IntPtr pAddr,
[OutAttribute()] System.IntPtr readLen);
这个函数调用语法
if( DivertRecv(handle, Ppacket, (uint)(8 * packet.Length-1),
Paddr, Ppacket_len) == false)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("warning: failed to read packet {0} .", Marshal.GetLastWin32Error());
Console.ResetColor();
Console.WriteLine(" Press any key to Exit ...");
Console.ReadKey();
Environment.Exit(1);
}
但是该函数每次调用都返回 false ,并且 GetLastWin32Error() 得到错误代码 998 。请帮助我。