1、定义头结点
typedef struct _DEVICE_EXTENSION {
.
.
.
LIST_ENTRY ReadQueue;
ULONG key;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
2、定义节点对像
typedef struct {
LIST_ENTRY list_entry;
ULONG key;
} MY_INFO,*PMY_INFO;
3、初始化头结点
InitializeListHead(&deviceExtension->ReadQueue);
4、插入节点
PMY_INFO info=(PMY_INFO)ExAllocatePoolWithTag(NonPagedPool,sizeof(MY_INFO),'SKY');
info->key=deviceExtension->key++;
InsertTailList(&deviceExtension->ReadQueue, &info->list_entry);
//InsertHeadList(&deviceExtension->ReadQueue, &info->list_entry);
5、遍历节点
PLIST_ENTRY first=NULL;
PLIST_ENTRY next=NULL;
PMY_INFO info=NULL;
first=&deviceExtension->ReadQueue;
for(next = first->Flink; next != first; next = next->Flink)
{
info = CONTAINING_RECORD(next, MY_INFO, list_entry);
}
6、遍历并删除节点
PLIST_ENTRY next=NULL;
PMY_INFO info=NULL;
while (!IsListEmpty(&deviceExtension->ReadQueue))
{
next = RemoveHeadList(&deviceExtension->ReadQueue);
info = CONTAINING_RECORD(next, MY_INFO, list_entry);
ExFreePool(info);
}
阅读(2309) | 评论(0) | 转发(0) |