练习一下DDK提供的链表

呵呵,我还处于入门新手菜鸟状态,,这些博文仅仅记录我的学习成长过程...


此处用到自定义结构,LIST_ENTRY, InitializeListHead,InsertTailList,RemoveTailList,CONTAINING_RECORD等宏或函数....


先定义


typedef struct _MyDataStruct{
	LIST_ENTRY myListEntry;
	ULONG x;
	ULONG y;
}MyDataStruct;


然后再写一段测试代码


	LIST_ENTRY listLinkHead;
	InitializeListHead(&listLinkHead);
	
	MyDataStruct *pMyDataStruct;
	ULONG i=0;
	KdPrint(("Start to insert into link list"));
	for(;i<10;i++){ pMyDataStruct=(MyDataStruct*)ExAllocatePool(PagedPool,sizeof(MyDataStruct)); pMyDataStruct->x=i+10;
		pMyDataStruct->y=i*10;
		InsertTailList(&listLinkHead,&pMyDataStruct->myListEntry);
	}
	KdPrint(("Inserted into link list"));

	while(!IsListEmpty(&listLinkHead)){
		PLIST_ENTRY pEntry=RemoveTailList(&listLinkHead);
		pMyDataStruct=CONTAINING_RECORD(pEntry,MyDataStruct,myListEntry);
		KdPrint(("x=%d,y=%d",pMyDataStruct->x,pMyDataStruct->y));
		ExFreePool(pMyDataStruct);
	}
评论列表