1 void IrpTest(PDRIVER_OBJECT DriverObject)
 2 {
 3     DriverObject->MajorFunction[IRP_MJ_CREATE] = HelloDDKDispatchRoutin;
 4     DriverObject->MajorFunction[IRP_MJ_CLOSE] = HelloDDKDispatchRoutin;
 5     DriverObject->MajorFunction[IRP_MJ_WRITE] = HelloDDKDispatchRoutin;
 6     DriverObject->MajorFunction[IRP_MJ_READ] = HelloDDKDispatchRoutin;
 7     DriverObject->MajorFunction[IRP_MJ_CLEANUP] = HelloDDKDispatchRoutin;
 8     DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = HelloDDKDispatchRoutin;
 9     DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = HelloDDKDispatchRoutin;
10     DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = HelloDDKDispatchRoutin;
11     DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = HelloDDKDispatchRoutin;
12 }
13 NTSTATUS HelloDDKDispatchRoutin(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp)
14 {
15     KdPrint(("Enter HelloDDKDispatchRoutin\n"));
16     
17     PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(pIrp);
18     static char* irpname[] =
19     {
20         "IRP_MJ_CREATE",
21         "IRP_MJ_CREATE_NAMED_PIPE",
22         "IRP_MJ_READ",
23         "IRP_MJ_WRITE",
24         "IRP_MJ_QUERY_INFORMATION",
25         "IRP_MJ_SET_INFORMATION",
26         "IRP_MJ_QUERY_EA",
27         "IRP_MJ_SET_EA",
28         "IRP_MJ_FLUSH_BUFFER",
29         "IRP_MJ_QUERY_VOLUME_INFORMATION",
30         "IRP_MJ_SET_VOLUME_INFORMATION",
31         "IRP_MJ_DIRECTORY_CONTROL",
32         "IRP_MJ_FILE_SYSTEM_CONTROL",
33         "IRP_MJ_DEVICE_CONTROL",
34         "IRP_MJ_INTERNAL_DEVICE_CONTROL",
35         "IRP_MJ_SHUTDOWN",
36         "IRP_MJ_LOCK_CONTROL",
37         "IRP_MJ_CLEARUP",
38         "IRP_MJ_CREATE_MAILSLOT",
39         "IRP_MJ_QUERY_SECURITY",
40         "IRP_MJ_SET_SECURITY",
41         "IRP_MJ_POWER",
42         "IRP_MJ_SYSTEM_CONTROL",
43         "IRP_MJ_DEVICE_CHANGE",
44         "IRP_MJ_QUOTA",
45         "IRP_MJ_PNP"
46     };
47     UCHAR type = stack->MajorFunction;
48 
49     if (type >= 26)
50     {
51         KdPrint(("Unknown IRP,major type %X\n", type));
52     }
53     else
54     {
55         KdPrint(("\t%s\n", irpname[type]));
56     }
57 
58     //这里处理自己想处理的
59 
60 
61     //结束IRP
62     NTSTATUS status = STATUS_SUCCESS;
63     pIrp->IoStatus.Status = status;//设置状态
64     pIrp->IoStatus.Information = 0;//操作字节
65     IoCompleteRequest(pIrp, IO_NO_INCREMENT);
66     KdPrint(("Leave HelloDDKDispatchRoutine\n"));
67     return status;
68 }