relax
驱动牛犊
驱动牛犊
  • 注册日期2001-06-19
  • 最后登录2012-09-06
  • 粉丝0
  • 关注0
  • 积分88分
  • 威望69点
  • 贡献值0点
  • 好评度8点
  • 原创分0分
  • 专家分0分
阅读:1808回复:4

关于IoGetDeviceObjectPointer()问题.

楼主#
更多 发布于:2001-07-10 16:14
我曾经在网上看到有人说IoGetDeviceObjectPointer()函数在windows 2000下获得下层设备指针时,有时会不正确,现在我正遇到这个问题,请问该如何解决?

最新喜欢:

dregsdregs
xuye
驱动小牛
驱动小牛
  • 注册日期2001-03-23
  • 最后登录2008-05-05
  • 粉丝0
  • 关注0
  • 积分40分
  • 威望4点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2001-07-10 16:54
详细点!
KDriver
驱动中牛
驱动中牛
  • 注册日期2001-06-09
  • 最后登录2008-09-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2001-07-12 08:47
[QUOTE]原本由 relax 发表
[B]我曾经在网上看到有人说IoGetDeviceObjectPointer()函数在windows 2000下获得下层设备指针时,有时会不正确,现在我正遇到这个问题,请问该如何解决? [/B][/QUOTE]

不知道你的FILEOBJECT设定的对不对?看看下面这段,是从WALTERONEY的书上摘来的。

Another common way to locate a device object is to start with an object name that you happen to know about:

PUNICODE_STRING DeviceName;   //  something gives you this
PDEVICE_OBJECT DeviceObject;  //  an output from this process
PFILE_OBJECT FileObject;      //  another output
NTSTATUS status = IoGetDeviceObjectPointer(DeviceName,
  <access mask>, &FileObject, &DeviceObject);

 


You get back a pointer to the device object having the name you specify and a pointer to a file object. A file object is the thing a file handle points to. Eventually, you'll need to dereference the file object, as shown here:

ObDereferenceObject(FileObject); //  DeviceObject now poison!

 


As soon as you dereference the file object, you also release your implicit reference to the device object. If you want to continue using the device object, be sure to reference it first:

ObReferenceObject(DeviceObject);
ObDereferenceObject(FileObject); //  DeviceObject still okay

 


You shouldn't automatically put the preceding two lines of code in your driver, however. In fact, when you send an IRP to a device object whose address you obtained by calling IoGetDeviceObjectPointer, you should send the address of the file object along:

PIRP Irp = IoBuildXxxRequest(...);
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
stack->FileObject = FileObject;
IoCallDriver(DeviceObject, Irp);

 


Here's the explanation for this extra statement. IoGetDeviceObjectPointer internally opens a regular handle to the device object, which causes the driver to receive an IRP_MJ_CREATE request with a pointer to the same file object you'll later be getting as a return value. The driver might create some auxiliary data structure that it associates with the file object, and it might require access to that structure to handle later IRPs. It will destroy that structure when it processes the IRP_MJ_CLOSE operation that occurs when the last reference to the file object disappears. For this to work right, you need to set the FileObject pointer in the first stack location for each IRP you send the driver.

You don't always set the file object pointer in a new IRP you create, by the way. If you're the driver that owns the file object by virtue of being the real implementor of IRP_MJ_CREATE, no one below you has any business looking at the file object. In the case I just described, however, the owner of the file object is the driver for the device object you found by calling IoGetDeviceObjectPointer. In that situation, you must set the file object pointer.
“萎软”,是Microsoft的小名!
fengdan
驱动牛犊
驱动牛犊
  • 注册日期2001-06-15
  • 最后登录
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2001-07-12 10:34
IoGetDeviceObjectPointer不会有问题的,我一直用得好好的
relax
驱动牛犊
驱动牛犊
  • 注册日期2001-06-19
  • 最后登录2012-09-06
  • 粉丝0
  • 关注0
  • 积分88分
  • 威望69点
  • 贡献值0点
  • 好评度8点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2001-07-12 11:19
我看到的是陆麟写的题为<<MS文档补充:IoGetDeviceObjectPointer >>的文章中提到的.
游客

返回顶部