阅读:1332回复:0
新手求助
读寒江独钓,串口过滤那里
我写了如下过程,运行到IoAttachDeviceToDeviceStack就蓝屏,求解 #include <ntddk.h> VOID Unload(PDRIVER_OBJECT driver) { DbgPrint("Unloading...\n"); } NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING path) { DEVICE_OBJECT newdevice;//过滤设备对象 DEVICE_OBJECT targetdevice;//目标设备对象 FILE_OBJECT fileobject;//过滤层文件对象 UNICODE_STRING comname;//设备名称 NTSTATUS status; PDEVICE_OBJECT poutdevice = NULL; #if DBG _asm int 3 #endif DbgPrint("begin...\n"); RtlInitUnicodeString(&comname, L"\\Device\\Serial0");//初始化设备名称字符串 status = IoGetDeviceObjectPointer(&comname, FILE_ALL_ACCESS, &fileobject, &targetdevice);//获取设备对象 if(status != STATUS_SUCCESS) { DbgPrint("获取串口设备对象失败!\n"); return status; } status = IoCreateDevice(driver, 0, NULL, targetdevice.DeviceType, 0, FALSE, &newdevice);//创建过滤设备 if(status != STATUS_SUCCESS) { DbgPrint("创建过滤设备失败!\n"); return status; } if(targetdevice.Flags & DO_BUFFERED_IO)//拷贝重要标志位 newdevice.Flags &= DO_BUFFERED_IO; if(targetdevice.Flags & DO_DIRECT_IO) newdevice.Flags &= DO_DIRECT_IO; if(targetdevice.Characteristics & FILE_DEVICE_SECURE_OPEN) newdevice.Characteristics |= FILE_DEVICE_SECURE_OPEN; newdevice.Flags |= DO_POWER_PAGABLE; poutdevice = IoAttachDeviceToDeviceStack(&newdevice, &targetdevice);//绑定设备 if(poutdevice == NULL) { DbgPrint("绑定设备失败!\n"); IoDeleteDevice(&fileobject); return status; } IoDeleteDevice(&fileobject); driver->DriverUnload = Unload; return STATUS_SUCCESS; } |
|