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

◎J!--这样实现动态数组????

楼主#
更多 发布于:2002-11-11 11:49
  看了一个极为诡异的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;
可以实现动态数组吗?

如何理解,请大虾不吝赐教
HonestTreee
cquwyb
驱动牛犊
驱动牛犊
  • 注册日期2002-05-10
  • 最后登录2010-10-23
  • 粉丝0
  • 关注0
  • 积分160分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-11-11 11:59

看了一个极为诡异的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 =
(PUSB_CONFIGURATION_DESCRIPTOR)descriptorBuffer;
descriptorBuffer = NULL;

} // get all configuration descriptors

问题是:deviceExtension->ConfigurationDescriptors =
(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:04
ft,还是有错!原文里的【i】变成斜体字啦!~

看了一个极为诡异的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:40
 :cool: :cool: :cool: :cool: :cool: :cool:
呵呵,漏了这样的声明:
deviceExtension->ConfigurationDescriptors = ExAllocatePool(NonPagedPool,
deviceExtension->DeviceDescriptor->bNumConfigurations *
sizeof(PUSB_CONFIGURATION_DESCRIPTOR));
这样才对嘛!

取消这个问题啦!~
HonestTreee
VanCheer
驱动老牛
驱动老牛
  • 注册日期2002-02-21
  • 最后登录2003-08-28
  • 粉丝0
  • 关注0
  • 积分-20分
  • 威望-10点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-11-11 12:44
:cool: :cool: :cool: :cool: :cool: :cool:
呵呵,漏了这样的声明:
deviceExtension->ConfigurationDescriptors = ExAllocatePool(NonPagedPool,
deviceExtension->DeviceDescriptor->bNumConfigurations *
sizeof(PUSB_CONFIGURATION_DESCRIPTOR));
这样才对嘛!

取消这个问题啦!~
 

放分庆祝吧
[img]http://www.driverdevelop.com/forum/upload/VanCheer/2003-03-21_mon.gif[/img][img]http://www.driverdevelop.com/forum/upload/VanCheer/2002-12-07_smallbaby.jpg[/img]
cquwyb
驱动牛犊
驱动牛犊
  • 注册日期2002-05-10
  • 最后登录2010-10-23
  • 粉丝0
  • 关注0
  • 积分160分
  • 威望16点
  • 贡献值0点
  • 好评度16点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2002-11-11 14:57
 :D :D :D :D :D :D
呵呵这个和尚到处化缘了啦!~(分不在多,心诚则零,emituofu!)
HonestTreee
游客

返回顶部