1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
Procedure TDriverInterfaceSPTI.GetUnitsFromClassDevices;
{--------------------------------------------
Scanne la classe CD-Rom
****
Sources :
http://msdn.microsoft.com/library/en-us/devio/base/setupdigetclassdevs.asp
---------------------------------------------}
const
FuncName : string = 'TDriverInterfaceSPTI.GetUnitsFromClassDevices';
var
DevList : HDEVINFO; // Liste des périphériques de type CD
DevI : Integer; // compteur, pour le Ieme périph de la liste
Success : Boolean;
DeviceInterfaceData: TSPDeviceInterfaceData;
DevData: TSPDevInfoData;
BytesReturned: DWORD;
FunctionClassDeviceData: PSPDeviceInterfaceDetailData;
aUnit : TUnitSPTI;
Begin
Self.DebugAddMsg(FuncName, '');
Self.Units.Clear; // Efface la liste des lecteurs
{ récupère la liste des périph CD }
DevList := SetupDiGetClassDevs(@CDROMCLASSGUID, nil, 0, DIGCF_PRESENT or DIGCF_INTERFACEDEVICE);
if (DevList = Pointer(INVALID_HANDLE_VALUE)) then Begin
Self.DebugAddMsg(FuncName, 'Impossible d''obtenir le handle sur la liste des cd');
Exit;
End;
{ information sur un périphérique de la liste }
DevI := 0;
Repeat
DeviceInterfaceData.cbSize := SizeOf(TSPDeviceInterfaceData);
Success := SetupDiEnumDeviceInterfaces(DevList, nil, CDROMCLASSGUID, DevI, DeviceInterfaceData);
if Success then begin
DevData.cbSize := SizeOf(DevData);
BytesReturned := 0;
SetupDiGetDeviceInterfaceDetail(DevList, @DeviceInterfaceData, nil, 0, BytesReturned, @DevData);
if (BytesReturned <> 0) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) then begin
FunctionClassDeviceData := AllocMem(BytesReturned);
FunctionClassDeviceData.cbSize := 5;
if SetupDiGetDeviceInterfaceDetail(DevList, @DeviceInterfaceData, FunctionClassDeviceData, BytesReturned, BytesReturned, @DevData) then Begin
MessageBox(0, PChar(@FunctionClassDeviceData.DevicePath), '', MB_OK);
aUnit := TUnitSPTI.Create(Self, PChar(@FunctionClassDeviceData.DevicePath));
Self.Units.Add(aUnit);
End;
End;
Inc(DevI,1);
End;
Until not Success;
End; |
Partager