为什么NdisFRegisterFilterDriver返回NDIS_STATUS_FAILURE?

我正在尝试编写一个NDIS中间filter驱动程序,但是在发生任何事情之前我都被卡住了。

我的代码还没有做任何事,除了试图注册filter驱动程序:

NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { NDIS_FILTER_DRIVER_CHARACTERISTICS FChars; NDIS_STRING ServiceName, UniqueName, FriendlyName; NDIS_STATUS Status; UNUSED(RegistryPath); g_FilterObject = DriverObject; RtlInitUnicodeString(&ServiceName, MIP_SERVICE_NAME); RtlInitUnicodeString(&FriendlyName, MIP_FRIENDLY_NAME); RtlInitUnicodeString(&UniqueName, MIP_UNIQUE_NAME); NdisZeroMemory(&FChars, sizeof(NDIS_FILTER_DRIVER_CHARACTERISTICS)); FChars.Header.Type = NDIS_OBJECT_TYPE_FILTER_DRIVER_CHARACTERISTICS; FChars.Header.Size = sizeof(NDIS_FILTER_DRIVER_CHARACTERISTICS); FChars.Header.Revision = NDIS_FILTER_CHARACTERISTICS_REVISION_1; FChars.MajorNdisVersion = 6; FChars.MinorNdisVersion = 0; FChars.MajorDriverVersion = 1; FChars.MinorDriverVersion = 0; FChars.Flags = 0; FChars.FriendlyName = FriendlyName; FChars.UniqueName = UniqueName; FChars.ServiceName = ServiceName; FChars.AttachHandler = FilterAttach; FChars.DetachHandler = FilterDetach; FChars.RestartHandler = FilterRestart; FChars.PauseHandler = FilterPause; FChars.SetOptionsHandler = FilterRegisterOptions; FChars.SetFilterModuleOptionsHandler = FilterSetModuleOptions; FChars.SendNetBufferListsHandler = FilterSend; FChars.ReturnNetBufferListsHandler = FilterReturnNetBufferLists; FChars.SendNetBufferListsCompleteHandler = FilterSendComplete; FChars.ReceiveNetBufferListsHandler = FilterReceive; FChars.CancelSendNetBufferListsHandler = FilterCancelSend; FChars.DevicePnPEventNotifyHandler = FilterDevicePnPEvent; FChars.NetPnPEventHandler = FilterNetPnPEvent; FChars.StatusHandler = FilterStatus; DriverObject->DriverUnload = FilterUnload; Status = NdisFRegisterFilterDriver(DriverObject, (NDIS_HANDLE)g_FilterObject, &FChars, &g_FilterHandle); if (Status != NDIS_STATUS_SUCCESS) { MDBG("Failed to register filter driver %x", Status); return Status; } return NDIS_STATUS_SUCCESS; } 

所有其他function都是空的(除了一些跟踪代码)。 他们在这里不重要。

NdisFRegisterFilterDriver总是返回NDIS_STATUS_FAILURE。 文档没有描述为什么会发生这种情况。 (它不应该是.inf文件的问题,因为我已经尝试从DDK的示例驱动程序的文字副本。)

我没有看到你发布的代码有什么问题。 是否将MIP_UNIQUE_NAME定义为 INF中的NetCfgInstanceId 相同 ? (顺便提一句,请记住生成一个与样本GUID不同的新GUID – 我已经看到了碰撞,而且并不美观)。