DPC定时器
KeInitializeTimer 初始化定时器 KeInitializeTimerEx 初始化定时器 KeSetTimer 开启定时器(只执行一次) KeSetTimerEx 开启定时器(可以设置循环) KeInitializeDpc 初始化DPC对象 KeCancelTimer 取消定时器 在驱动中是以100纳秒为单位的 1000纳秒=1微秒 1000微秒=1毫秒 1000毫秒=1秒 10*1000*1000 KTIMER my_timer;//注意要定义全局变量 KDPC KiTimerExpireDpc;//注意要定义全局变量 LARGE_INTEGER duetime = { 0 }; KeInitializeTimerEx(&my_timer, NotificationTimer); KeInitializeDpc(&KiTimerExpireDpc, (PKDEFERRED_ROUTINE)KiTimerExpirationFunction, NULL); KeSetTimerEx(&my_timer, duetime, 1000, &KiTimerExpireDpc); VOID KiTimerExpirationFunction(IN struct _KDPC *Dpc,IN PVOID DeferredContext,IN PVOID SystemArgument1,IN PVOID SystemArgument2 ) { KdPrint(("定时器....................\n")); }; KeCancelTimer(&my_timer);//取消定时器 另外一种方法/////////////////////////////// typedef struct _DEVICE_EXTENSION { LIST_ENTRY list_head; KSPIN_LOCK list_lock; PVOID thread_pointer; BOOLEAN terminate_thread; KEVENT request_event; KTIMER my_timer; KDPC KiTimerExpireDpc; } DEVICE_EXTENSION, *PDEVICE_EXTENSION; //创建设备 IoCreateDevice(pDriverObj,sizeof(DEVICE_EXTENSION),NULL,FILE_DEVICE_UNKNOWN,0,FALSE,&device_object); device_extension = (PDEVICE_EXTENSION)device_object->DeviceExtension; //初始化定时器 KeInitializeTimerEx(&device_extension->my_timer, NotificationTimer); // 初始化定时器过程的DPC对象 KeInitializeDpc(&device_extension->KiTimerExpireDpc,(PKDEFERRED_ROUTINE)KiTimerExpirationFunction, NULL); //启动定时器 KeSetTimerEx(&device_extension->my_timer, duetime, 1000, &device_extension->KiTimerExpireDpc); device_extension->terminate_thread = FALSE; PDEVICE_EXTENSION device_extension; device_extension = (PDEVICE_EXTENSION)pDriverObj->DeviceObject->DeviceExtension; //取消定时器 KeCancelTimer(&device_extension->my_timer);