阅读:1508回复:2
<Programming the Windows Driver Model>一书中一个范例代码的疑问
extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath) { DriverObject->DriverUnload = DriverUnload; DriverObject->DriverExtension->AddDevice = AddDevice; DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp; DriverObject->MajorFunction[IRP_MJ_POWER] = DispatchPower; DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = DispatchWmi; servkey.Buffer = (PWSTR) ExAllocatePool(PagedPool, RegistryPath->Length + sizeof(WCHAR)); if (!servkey.Buffer) return STATUS_INSUFFICIENT_RESOURCES; servkey.MaximumLength = RegistryPath->Length + sizeof(WCHAR); RtlCopyUnicodeString(&servkey, RegistryPath); servkey.Buffer[RegistryPath->Length/sizeof(WCHAR)] = 0; return STATUS_SUCCESS; } 其中ExAllocatePool函数第二个参数为什么是RegistryPath->Length + sizeof(WCHAR)而不是RegistryPath->Length? 作者考虑了对齐后可能pool不够用?还是其他因素? 本人初学驱动,各位帮帮忙,谢谢! |
|
沙发#
发布于:2008-07-25 19:35
字符串结束符 0x0000
|
|
板凳#
发布于:2008-07-25 20:58
Re:<Programming the Windows Driver Model>一书中一
谢谢楼上的牛人!windows编程的数据类型可真是蛮搞的~ 我都把Length的类型当成WCHAR了~ |
|