阅读:1423回复:5
◎J!--这样实现动态数组????
看了一个极为诡异的USB驱动例子
例子的用意是利用deviceExtention来保存USB设备的configuration描述符由于事先不可能知道有多少个configuration描述符,例子想用所谓的动态数组吧(i guess): typedef struct _DEVICE_EXTENSION{ ??? PUSB_DEVICE_DESCRIPTOR DeviceDescriptor; // keep an array of pointers to the configuration descriptor PUSB_CONFIGURATION_DESCRIPTOR * ConfigurationDescriptors; ??? } DEVICE_EXTENSION, *PDEVICE_EXTENSION; 然后这样使用它来保存取到的configuration descriptor,对吗 ??? for (i = 0; i < deviceExtension->DeviceDescriptor->bNumConfigurations; i++) { // Get the configuration descriptor (first 9 bytes) UCHAR tempBuffer[9]; descriptorBuffer = &tempBuffer; if (!descriptorBuffer) { ntStatus = STATUS_NO_MEMORY; return ntStatus; } ntStatus = GetDescriptor(DeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, (UCHAR)i, 0, descriptorBuffer, siz); if (!NT_SUCCESS(ntStatus)) { return ntStatus; } // Now get the rest of the configuration descriptor & save siz = ((PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer)->wTotalLength; descriptorBuffer = ExAllocatePool(NonPagedPool, siz); if (!descriptorBuffer) { ntStatus = STATUS_NO_MEMORY; return ntStatus; } ntStatus = GetDescriptor(DeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, (UCHAR)i, 0, descriptorBuffer, siz); if (!NT_SUCCESS(ntStatus)) { goto StartDeviceEnd; } deviceExtension->ConfigurationDescriptors = (PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer; descriptorBuffer = NULL; } // get all configuration descriptors 问题是:deviceExtension->ConfigurationDescriptors = (PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer; descriptorBuffer = NULL;可以实现动态数组吗? 如何理解,请大虾不吝赐教 |
|
|
沙发#
发布于:2002-11-11 11:59
上面有错,这样好看一些 |
|
|
板凳#
发布于:2002-11-11 12:04
ft,还是有错!原文里的【i】变成斜体字啦!~
上面有错,这样好看一些 |
|
|
地板#
发布于:2002-11-11 12:40
:cool: :cool: :cool: :cool: :cool: :cool:
呵呵,漏了这样的声明: deviceExtension->ConfigurationDescriptors = ExAllocatePool(NonPagedPool, deviceExtension->DeviceDescriptor->bNumConfigurations * sizeof(PUSB_CONFIGURATION_DESCRIPTOR)); 这样才对嘛! 取消这个问题啦!~ |
|
|
地下室#
发布于:2002-11-11 12:44
:cool: :cool: :cool: :cool: :cool: :cool: 放分庆祝吧 |
|
|
5楼#
发布于:2002-11-11 14:57
:D :D :D :D :D :D
呵呵这个和尚到处化缘了啦!~(分不在多,心诚则零,emituofu!) |
|
|