阅读:1087回复:1
看看这段代码,为什么‘IoGetDeviceProperty’老是异常,计算机崩溃呢?
NTSTATUS Status;
UNICODE_STRING DeviceName; ULONG HarkDiskNumber; ULONG PartitionNumber; char nnn[256]; ANSI_STRING aIdName; WCHAR ubuf[256]; UNICODE_STRING ddddd; PDEVICE_OBJECT DiskDeviceObjects = NULL; PFILE_OBJECT DiskFileObjects = NULL; PWCHAR szGUID = NULL; PAGED_CODE(); ddddd.Buffer = ubuf; ddddd.MaximumLength = 256; HarkDiskNumber = 0; sprintf(nnn, \"\\\\DosDevices\\\\PhysicalDrive%d\", HarkDiskNumber); aIdName.Length = strlen(nnn); aIdName.MaximumLength = aIdName.Length+1; aIdName.Buffer = nnn; Status = RtlAnsiStringToUnicodeString(&ddddd, &aIdName,FALSE ); if (NT_SUCCESS(Status)) DbgPrint(\"\"); else { DbgPrint(\"Error converting ansi string to unicode string: %08lx.\\n\", Status); goto FINALLY; } Status = IoGetDeviceObjectPointer(&ddddd, FILE_READ_DATA | FILE_WRITE_DATA, &DiskFileObjects, &DiskDeviceObjects); if (! NT_SUCCESS(Status)) { DbgPrint(\"Error GetDeviceObjectPointer: %08lx.\\n\", Status); goto FINALLY; } else { DbgPrint(\"IoGetDeviceObjectPointer ok\"); } lResultLenght = 0; Status = IoGetDeviceProperty(DiskDeviceObjects, DevicePropertyPhysicalDeviceObjectName, lResultLenght, szGUID, &lResultLenght); if (Status == STATUS_BUFFER_TOO_SMALL && lResultLenght != 0) { szGUID = ExAllocatePool (NonPagedPool, lResultLenght); if (szGUID == NULL) { DebugPrint(\"Check disk Error: IoGetDeviceProperty: %08lx.\\n\", Status); goto FINALLY; } } else { DebugPrint(\"Check disk Error: IoGetDeviceProperty: %08lx.\\n\", Status); goto FINALLY; } Status = IoGetDeviceProperty(DiskDeviceObjects, DevicePropertyClassGuid, lResultLenght, szGUID, &lResultLenght); if (! NT_SUCCESS(Status)) { DebugPrint(\"Check disk Error: IoGetDeviceProperty: %08lx.\\n\", Status); goto FINALLY; } ............. [编辑 - 10/22/02 by LarryWang1234] |
|
沙发#
发布于:2002-10-24 09:46
为什么‘IoGetDeviceProperty’不能工作啊???
那位大侠帮忙看看啊,我快受不了了,DDK快把我搞死了!! |
|