[an error occurred while processing this directive]
Посмотрите, например сдесь (+)
(«Телесистемы»: Конференция «Цифровые сигнальные процессоры (DSP) и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено PicoDev2 22 февраля 2005 г. 01:10
В ответ на: Как правильно обращатся у USB Устройствам в Windows Me и XP. отправлено misyachniy 21 февраля 2005 г. 10:49

C:\WinDDK\3790_1433\src\wdm\usb\bulkusb\exe

SetupDiGetClassDevs
SetupDiGetDeviceInterfaceDetail
=====================================================================
HANDLE
OpenUsbDevice( LPGUID pGuid, char *outNameBuf)
/*++
Routine Description:

Do the required PnP things in order to find the next available
proper device in the system at this time.

Arguments:

pGuid: ptr to GUID registered by the driver itself
outNameBuf: the generated name for this device

Return Value:

return HANDLE if the open and initialization was successful,
else INVLAID_HANDLE_VALUE.
--*/
{
ULONG NumberDevices;
HANDLE hOut = INVALID_HANDLE_VALUE;
HDEVINFO hardwareDeviceInfo;
SP_DEVICE_INTERFACE_DATA deviceInfoData;
ULONG i;
BOOLEAN done;
PUSB_DEVICE_DESCRIPTOR usbDeviceInst;
PUSB_DEVICE_DESCRIPTOR *UsbDevices = &usbDeviceInst;
PUSB_DEVICE_DESCRIPTOR tempDevDesc;

*UsbDevices = NULL;
tempDevDesc = NULL;
NumberDevices = 0;

//
// Open a handle to the plug and play dev node.
// SetupDiGetClassDevs() returns a device information set that contains info on all
// installed devices of a specified class.
//
hardwareDeviceInfo = SetupDiGetClassDevs(
pGuid,
NULL, // Define no enumerator (global)
NULL, // Define no
(DIGCF_PRESENT | // Only Devices present
DIGCF_DEVICEINTERFACE)); // Function class devices.

//
// Take a wild guess at the number of devices we have;
// Be prepared to realloc and retry if there are more than we guessed
//
NumberDevices = 4;
done = FALSE;
deviceInfoData.cbSize = sizeof (SP_DEVICE_INTERFACE_DATA);

i=0;

while (!done)
{
NumberDevices *= 2;

if (*UsbDevices)
{
tempDevDesc = realloc(*UsbDevices,
(NumberDevices * sizeof (USB_DEVICE_DESCRIPTOR)));

if (tempDevDesc)
{
*UsbDevices = tempDevDesc;
tempDevDesc = NULL;
}
else
{
free(*UsbDevices);
*UsbDevices = NULL;
}
}
else
{
*UsbDevices = calloc(NumberDevices,
sizeof (USB_DEVICE_DESCRIPTOR));
}

if (NULL == *UsbDevices)
{
// SetupDiDestroyDeviceInfoList destroys a device information set
// and frees all associated memory.
//
SetupDiDestroyDeviceInfoList(hardwareDeviceInfo);

return INVALID_HANDLE_VALUE;
}

usbDeviceInst = *UsbDevices + i;

for (; i < NumberDevices; i++)
{
// SetupDiEnumDeviceInterfaces() returns information about
// device interfaces exposed by one or more devices. Each call
// returns information about one interface; the routine can be
// called repeatedly to get information about several
// interfaces exposed by one or more devices.
//
if (SetupDiEnumDeviceInterfaces(hardwareDeviceInfo,
0, // We don't care about specific PDOs
pGuid,
i,
&deviceInfoData))
{
hOut = OpenOneDevice(hardwareDeviceInfo,
&deviceInfoData,
outNameBuf);

if (hOut != INVALID_HANDLE_VALUE)
{
done = TRUE;
break;
}
}
else
{
if (ERROR_NO_MORE_ITEMS == GetLastError())
{
done = TRUE;
break;
}
}
}
}

NumberDevices = i;

// SetupDiDestroyDeviceInfoList() destroys a device information set
// and frees all associated memory.
//
SetupDiDestroyDeviceInfoList (hardwareDeviceInfo);

free (*UsbDevices);

return hOut;
}

Составить ответ  |||  Конференция  |||  Архив

Ответы


Отправка ответа

Имя (обязательно): 
Пароль: 
E-mail: 

Тема (обязательно):
Сообщение:

Ссылка на URL: 
Название ссылки: 

URL изображения: 


Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru