.
.
.
Const
//La interface GUID ubicada en al seccion [Dev_AddReg] del .inf
GUID_DEVINTERFACE: TGUID = '{9FD6FF49-05EC-49C4-9B78-371937D1E315}';
//constante para la funcion WinUsb_QueryDeviceInformation - referirse a la doc de la WinUSB
DEVICE_SPEED = $001;
.
.
.
//SetupApi unidad de la JEDI API Library
uses WINUSBDll, TypesDll, SetupApi;
.
.
.
//casi todas las funciones aqui son de la SetupApi
//documentacion al respecto en la ayuda de: visual studio,
//C++/Delphi 2009, Windows Driver Kit(WDK)
function TForm1.GetDevicePath: THandle;
var
BytesReturned : DWORD;
LPGUID : TGUID;
DeviceInfo : HDEVINFO;
DeviceInterfaceData : TSPDeviceInterfaceData;
DetailData : PSPDeviceInterfaceDetailData;
begin
LPGUID := GUID_DEVINTERFACE;
DetailData:= nil;
GetDevicePath:= INVALID_HANDLE_VALUE;
//SetupDiGetClassDevs : obtiene un handle hacia la informacion de la device
DeviceInfo:=SetupDiGetClassDevs(@LPGUID, nil, 0, DIGCF_PRESENT or DIGCF_DEVICEINTERFACE);
if not(DeviceInfo = Pointer(INVALID_HANDLE_VALUE)) then
begin
//inicializa la estructura TSPDeviceInterfaceData
DeviceInterfaceData.cbSize := SizeOf(TSPDeviceInterfaceData);
//SetupDiEnumDeviceInterfaces : enumera todas las interfaces de las devices
if SetupDiEnumDeviceInterfaces(DeviceInfo, nil, LPGUID, 0, DeviceInterfaceData) then
begin
//SetupDiGetDeviceInterfaceDetail : obtiene detalles de la informacion de la interface
//de nuestra deviceestos datos son almacenados en la estructura TSPDeviceInterfaceDetailData
if not SetupDiGetDeviceInterfaceDetail(DeviceInfo, @DeviceInterfaceData, nil, 0,
BytesReturned, nil) then
begin
DetailData := AllocMem(BytesReturned);
if DetailData = Pointer(INVALID_HANDLE_VALUE) then
begin
SetupDiDestroyDeviceInfoList(DeviceInfo);
GetDevicePath:=INVALID_HANDLE_VALUE;
end;
DetailData.cbSize:= SizeOf(TSPDeviceInterfaceDetailData);
//SetupDiGetDeviceInterfaceDetail : obtiene el tamño correcto para la estructura
//TSPDeviceInterfaceDetailData
if SetupDiGetDeviceInterfaceDetail(DeviceInfo, @DeviceInterfaceData, DetailData,
BytesReturned, BytesReturned, nil) = false then
begin
FreeMem(DetailData);
GetDevicePath:=INVALID_HANDLE_VALUE;
end;
if DetailData.DevicePath = '' then
begin
SetupDiDestroyDeviceInfoList(DeviceInfo);
FreeMem(DetailData);
end;
//obtenemos un handle para la device
GetDevicePath := CreateFile(DetailData.DevicePath, GENERIC_WRITE or GENERIC_READ,
FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0 );
FreeMem(DetailData);
end;
end;
end;
end;