unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, SetupAPI, Hid;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
const MAX_DETAIL_BUFF_LEN = 256;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var MyGuid : TGUID;
hHDEVINFO : HDEVINFO;
MyInterface : TSPDeviceInterfaceData;
bSuccess : Boolean;
MyDetail : array[0..MAX_DETAIL_BUFF_LEN-1] of byte;
PMyDetail : PSPDeviceInterfaceDetailData;
begin
//这个是正确的guid:A5DCBF10-6530-11D2-901F-00C04FB951ED
MyGuid.D1 := $A5DCBF10;
MyGuid.D2 := $6530;
MyGuid.D3 := $11D2;
MyGuid.D4[0]:= $90;
MyGuid.D4[1]:= $1F;
MyGuid.D4[2]:= $00;
MyGuid.D4[3]:= $C0;
MyGuid.D4[4]:= $4F;
MyGuid.D4[5]:= $B9;
MyGuid.D4[6]:= $51;
MyGuid.D4[7]:= $ED;
hHDEVINFO := SetupDiGetClassDevs(@MyGuid, nil, 0, DIGCF_DEVICEINTERFACE+DIGCF_PRESENT);
if (DWORD(hHDEVINFO) <> INVALID_HANDLE_VALUE) then
begin
MyInterface.cbSize := sizeof(TSPDeviceInterfaceData);
bSuccess := SetupDiEnumDeviceInterfaces(hHDEVINFO, nil, MyGuid, 0, MyInterface);
if not bSuccess then
SetupDiDestroyDeviceInfoList(hHDEVINFO)
else
begin
ZeroMemory(@MyDetail, MAX_DETAIL_BUFF_LEN);
PMyDetail := @MyDetail;
PMyDetail.cbSize := sizeof(TSPDeviceInterfaceDetailData);
if not SetupDiGetDeviceInterfaceDetail(hHDEVINFO,@MyInterface, @MyDetail, MAX_DETAIL_BUFF_LEN, nil, nil) then
SetupDiDestroyDeviceInfoList(hHDEVINFO)
else
ShowMessage(StrPas(PMyDetail.DevicePath));
end;
end;
end;
end.
测试没有通过。