LarryWang1234
驱动牛犊
驱动牛犊
  • 注册日期2002-10-22
  • 最后登录2003-01-16
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1087回复:1

看看这段代码,为什么‘IoGetDeviceProperty’老是异常,计算机崩溃呢?

楼主#
更多 发布于:2002-10-22 10:29
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]
LarryWang1234
驱动牛犊
驱动牛犊
  • 注册日期2002-10-22
  • 最后登录2003-01-16
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-10-24 09:46
为什么‘IoGetDeviceProperty’不能工作啊???
那位大侠帮忙看看啊,我快受不了了,DDK快把我搞死了!!
游客

返回顶部