问题描述
|
您好想使用IoRegisterPlugPlayNotification通知新的USB获取插件!我的代码不起作用(我没有得到通知)
可以在DriverEntry中使用IoRegisterPlugPlayNotification?
没有使用Adddevice我可以得到通知吗?
我必须使用INF文件来获得通知吗?为什么呢?
我必须使用什么GUID?在代码和INF文件中?
NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
int i;
//{a5dcbf10-6530-11d2-901f-00c04fb951ed}
DriverObject->DriverUnload=usblockerUnload;
for (i=0;i<IRP_MJ_MAXIMUM_FUNCTION;i++)
DriverObject->MajorFunction[i] = Driver_PNP;
DriverObject->MajorFunction[IRP_MJ_PNP] = Driver_PNP;
status=IoRegisterPlugPlayNotification( EventCategoryDeviceInterfaceChange,PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,(PVOID)&GUID_CLASS_USB_DEVICE,DriverObject,(PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)PnpNotifyInterfaceChange,(PVOID)DriverObject,&NotificationHandle);
if(!NT_SUCCESS(status))
{
DbgPrint(\"error in IoRegisterPlugPlayNotification \\n\");
return status;
}
DbgPrint(\" Driver Entry oK *** \\n\");
return STATUS_SUCCESS;
}
void usblockerUnload(IN PDRIVER_OBJECT DriverObject)
{
NTSTATUS status;
DbgPrint(\" Unload \\r\");
status=IoUnregisterPlugPlayNotification(NotificationHandle);
if(!NT_SUCCESS(status))
{
DbgPrint(\"error in IoUnregisterPlugPlayNotification \\n\");
}
}
#pragma PAGEDCODE
NTSTATUS PnpNotifyInterfaceChange( PVOID pNotifyContext,PVOID pContext )
{
PDEVICE_INTERFACE_CHANGE_NOTIFICATION pNotifyData = (PDEVICE_INTERFACE_CHANGE_NOTIFICATION)pNotifyContext;
DbgPrint(\"symbolic name: %wZ\\n\",pNotifyData->SymbolicLinkName);
return STATUS_SUCCESS;
}
解决方法
您正在尝试编写NT样式的驱动程序(也称为旧版驱动程序)。您不需要使用.INF文件进行安装;只需将其安装为服务并按1即可(或在服务属性中将其启动设置为“自动”)。
附带说明:确保您真正了解自己在做什么。您似乎混淆了主题。例如,NT样式的驱动程序不处理IRP_MJ_PNP,它根本不会接收它们。当然,您仍然可以注册PnP通知:您将在回调函数中收到它们,但与IRP_MJ_PNP无关。