1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/*使用ExAllocatePool函数分配内存 by exchen 2009-10-03 */ #include <ntddk.h> #define BUFFER_SIZE 256 VOID DriverUnload( IN PDRIVER_OBJECT DriverObject ) { DbgPrint("驱动已经被停止了\n"); } NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { UNICODE_STRING usBuff; UNICODE_STRING usCopyDes; RtlInitUnicodeString(&usBuff,L"My String"); usCopyDes.Buffer=(PWSTR)ExAllocatePool(PagedPool,BUFFER_SIZE); //分配内存 usCopyDes.MaximumLength=BUFFER_SIZE; RtlCopyUnicodeString(&usCopyDes,&usBuff);//拷贝字符串 DbgPrint("拷贝为:%wZ",&usCopyDes); //打印拷贝内容 RtlFreeUnicodeString(&usCopyDes); //释放分配的空间 DriverObject->DriverUnload = DriverUnload; return STATUS_SUCCESS; } |