delphi imagen usb vid&pid

procedure FillFilterGuidList(clid: TGUID; list: TStringList);
{ sub function}
function FormattedKeystring (DisplayName, FriendlyName: string): string;
var
   c: Char;
   i: Integer;
   Temp: string;
   Value: string;
begin
   Value := DisplayName + FriendlyName;
   Temp := '';
   for i := 1 to Length (Value) do begin
      c:= Value[i];
      (*if c in ['\'] then begin
         c := ' ';
      end;*)
      if (c in [' ','-','{','}'])
       or (c in ['a'..'z'])
       or (c in ['A'..'Z'])
       or (c in ['0'..'9']) then begin
         Temp := Temp + c;
      end;
   end;
   Result := Temp;
end;


var
  pSysDevEnum: IIECreateDevEnum;
  pEnumCat: IIEEnumMoniker;
  pMoniker: IIEMoniker;
  cFetched: ULONG;
  pPropBag: IIEPropertyBag;
  bc: IIEBindCtx;
  mo: IIEMoniker;
  er: IIEErrorLog;
  ov: OleVariant;
  sName: POleStr;
  DisplayName:string;
begin
  list.clear;
  pSysDevEnum := nil;  
  CoCreateInstance(CLSID_SystemDeviceEnum, nil, CLSCTX_INPROC, IID_IIECreateDevEnum, pSysDevEnum);
  pEnumCat := nil;
  if pSysDevEnum.CreateClassEnumerator(clid, pEnumCat, 0) = S_OK then
  begin
    pMoniker := nil;
    while pEnumCat.Next(1, pMoniker, @cFetched) = S_OK do
    begin
      bc := nil;
      mo := nil;


      
      if pMoniker.GetDisplayName (nil, nil, sName) = S_OK then begin
        DisplayName := sName;
        CoTaskMemFree (sName);
      end
      else begin
        DisplayName := '';
      end;


      list.Add(FormattedKeystring(DisplayName,''));


//      pMoniker.BindToStorage(bc, mo, IID_IIEPropertyBag, pPropBag);
//      er := nil;
//      pPropBag.Read('CLSID', ov, er);
//      list.Add(string(AnsiString(ov)));
//      pPropBag := nil;
      pMoniker := nil;
    end;
  end;
  pEnumCat := nil;
  pSysDevEnum := nil;
end;

你可能感兴趣的:(delphi imagen usb vid&pid)