cquwyb
驱动牛犊
驱动牛犊
  • 注册日期2002-05-10
  • 最后登录2010-10-23
  • 粉丝0
  • 关注0
  • 积分160分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
阅读:1036回复:1

◎L×--内核模式里的动态数组??(获取USB配置描述符)

楼主#
更多 发布于:2002-11-11 12:08

看了一个极为诡异的USB驱动例子
例子的用意是利用deviceExtention来保存USB设备的configuration描述符由于事先不可能知道有多少个configuration描述符,例子想用所谓的动态数组吧(i guess):

typedef struct _DEVICE_EXTENSION{
???
PUSB_DEVICE_DESCRIPTOR DeviceDescriptor;
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,
size);
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
// Now get the rest of the configuration descriptor & save
size = ((PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer)->wTotalLength;
descriptorBuffer = ExAllocatePool(NonPagedPool, size);
if (!descriptorBuffer)
{
ntStatus = STATUS_NO_MEMORY;
return ntStatus;
}
ntStatus = GetDescriptor(DeviceObject,
USB_CONFIGURATION_DESCRIPTOR_TYPE,
(UCHAR)i,
0,
descriptorBuffer,
size);
if (!NT_SUCCESS(ntStatus))
{
return ntStatus;
}
deviceExtension->ConfigurationDescriptors【i】 =
(PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer;
descriptorBuffer = NULL;

} // get all configuration descriptors

问题是:deviceExtension->ConfigurationDescriptors【i】 =
(PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer;
descriptorBuffer = NULL;可以实现动态数组吗?

如何理解,请大虾不吝赐教
HonestTreee
cquwyb
驱动牛犊
驱动牛犊
  • 注册日期2002-05-10
  • 最后登录2010-10-23
  • 粉丝0
  • 关注0
  • 积分160分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-11-11 12:38
呵呵,漏了这样的声明:
deviceExtension->ConfigurationDescriptors = ExAllocatePool(NonPagedPool,
deviceExtension->DeviceDescriptor->bNumConfigurations *
sizeof(PUSB_CONFIGURATION_DESCRIPTOR));

这样才对嘛!

取消这个问题啦!~
HonestTreee
游客

返回顶部