Code Example: A Loopback Device

An interesting (albeit simplistic) example to consider is a loopback device. The driver processes write requests by reserving a paged pool buffer and copying user data into this temporary buffer. The buffer is retained until such time as a read request is issued. The data returned by the read request is the contents of the temporary buffer, which is then released. The example demonstrates the implementation of read and write Dispatch routines as well as user buffer access.

 NTSTATUS DispatchWrite( INPDEVICE_OBJECT pDO IN PIRP pIrp) { NTSTATUS status = STATUS_SUCCESS; PDEVICE_EXTENSION pDE; PVOID userBuffer; ULONG xferSize; // The stack location contains the user buffer info PIO_STACK_LOCATION pIrpStack; pIrpStack ...

Get Windows® 2000 Device Driver Book: A Guide for Programmers, Second Edition, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.