Windows驱动编程基础教程-谭文-代码整理
代码全部测试通过,测试环境:WinDDK chk x86 WXP
教程上有很详细非常详细的讲解,偶就偷懒不写注释了
代码中有些应该考虑应该实现的东西偶不会,就省了。。。不会完善,能跑就行。。。
1 字符串使用
2 内存的分配与释放
3 LIST_ENTRY
4 LARGE_INTEGER
5 KSPIN_LOCK
6 文件操作
7 注册表读写
8 时间与定时
未完待续。。。
makefile
#
# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
# file to ponent. This file merely indirects to the real make file
# that is shared by all the ponents of the Windows NT DDK
#
!INCLUDE $(NTMAKEENV)\
sources
TARGETNAME=study
TARGETPATH=OBJ
TARGETTYPE=DRIVER
SOURCES=
1 字符串使用
/*
*《Windows驱动编程基础教程-谭文》-字符串使用
*测试环境:WinDDK chk x86 WXP
*小默 整理
*/
#include<>
#include<>
DRIVER_UNLOAD StudyUnload;
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject,PUNICODE_STRING RegistryPath)
{
PAGED_CODE();
DriverObject->DriverUnload = StudyUnload;
return ESS;
}
VOID StudyUnload(PDRIVER_OBJECT DriverObject)
{
UNICODE_STRING str1;
UNICODE_STRING dst;
WCHAR dst_buf[256];
UNICODE_STRING src = RTL_CONSTANT_STRING(L"source string"); //Init a UNICODE_STRING
NTSTATUS status;
PAGED_CODE();
DbgPrint("Study:Our driver is unloading\r\n");
//Init a UNICODE_STRING
RtlInitUnicodeString(&str1,L"Init the string str1");
KdPrint(("Init a UNICODE_STRING:%wZ\r\n",&str1));
//把dst初始化成拥有缓冲区长度为256的UNICODE_STRING空串
//!!! copy 之前一定要先给dst分配空间!!!
RtlInitEmptyUnicodeString(&dst,dst_buf,256*sizeof(WCHAR));
//copy a UNICODE_STRING
RtlCopyUnicodeString(&dst,&src);
KdPrint(("Copy a UNICODE_STRING:%wZ\r\n",&dst));
//append a UNICODE_STRING
status = RtlAppendUnicodeToString(&dst,L"|append string.");
KdPrint(("Append a UNICODE_STRING:%wZ\r\n",&dst));
return;
}
2 内存的分配与释放
/*
*《Windows驱动编程基础教程-谭文》-内存的分配与释放
*测试环境:WinDDK chk x86 WXP
*小默 整理
*/
#include<>
#include<>
//定义一个内存分配标记
#define MEM_TAG "CG"
DRIVER_UNLOAD StudyUn
Windows驱动编程基础教程 来自淘豆网www.taodocs.com转载请标明出处.