Показать сообщение отдельно
  #4  
Старый 24.09.2007, 17:35
~ SaM ~ ~ SaM ~ вне форума
Начинающий
 
Регистрация: 05.01.2007
Адрес: Днепропетровск
Сообщения: 141
Репутация: 25
По умолчанию

Лови!


Код:
type
 SP_DEVINFO_DATA=record
  cbSize:DWord;
  ClassGuid:TGuid;
  DevInst:DWord;
  Reserved:LongInt;
 end;

 PSP_DEVINFO_DATA=^SP_DEVINFO_DATA;
 PGuid=^TGuid;

const
 DIGCF_ALLCLASSES=$00000004;
 DIGCF_PRESENT=$00000002;
 DIGCF_PROFILE=$00000008;
 DIGCF_DEVICEINTERFACE=$00000010;
 SPDRP_DEVICEDESC=$00000000;


 function SetupDiCreateDeviceInfoList(ClassGuid:PGuid;
  hwndParent:cardinal):Pointer; stdcall;
  external 'setupapi.dll';
 function SetupDiGetClassDevsExA(ClassGuid:PGuid; Enumerator:PChar;
  hwndParent:cardinal; Flags:DWord; DeviceInfoSet:Pointer;
  MachineName:PChar; Reserved:DWord):Pointer; stdcall;
  external 'setupapi.dll';
 function SetupDiGetDeviceRegistryPropertyA(DeviceInfoSet:Pointer;
  DeviceInfoData:PSP_DEVINFO_DATA; Property_:DWord; PropertyRegDataType:Pointer;
  PropertyBuffer:Pointer; PropertyBufferSize:cardinal; RequiredSize:Pointer):
  longbool; stdcall;
  external 'setupapi.dll';
 function SetupDiEnumDeviceInfo(DeviceInfoSet:Pointer; MemberIndex:DWord;
  var DeviceInfoData:SP_DEVINFO_DATA):longbool; stdcall;
  external 'setupapi.dll';
 function SetupDiDestroyDeviceInfoList(DeviceInfoSet:Pointer):longbool; stdcall;
  external 'setupapi.dll';


procedure TForm1.Button2Click(Sender: TObject);
var
 hAllDevices, hDev:Pointer;
 k:Integer;
 Data:SP_DEVINFO_DATA;
 dwInfo, dwRequired, sz:DWord;
 buf:PChar;
 g:TGuid;
 s:string;
begin
hDev:=SetupDiCreateDeviceInfoList(nil, 0);
k:=GetLastError;
ShowMessage(IntToStr(k));
g:=StringToGuid('{4D36E96D-E325-11CE-BFC1-08002BE10318}');
hAllDevices:=SetupDiGetClassDevsExA(@g, nil, 0, DIGCF_PRESENT {or DIGCF_ALLCLASSES},
 hDev, nil, 0);
k:=GetLastError;
ShowMessage(IntToStr(k));
FillChar(Data, SizeOf(SP_DEVINFO_DATA), 0);
Data.cbSize:=SizeOf(SP_DEVINFO_DATA);
dwInfo:=0;
If not SetupDiEnumDeviceInfo(hAllDevices, dwInfo, Data) then
ShowMessage('Error');
While SetupDiEnumDeviceInfo(hAllDevices, dwInfo, Data) do
begin
 dwRequired:=0;
 If (not SetupDiGetDeviceRegistryPropertyA(hAllDevices, @Data,
  SPDRP_DEVICEDESC,
  nil, nil, 0, @dwRequired)) and (GetLastError=ERROR_INSUFFICIENT_BUFFER) then
 begin
  sz:=dwRequired;
  buf:=StrAlloc(100);
  FillChar(buf^, 100, #0);
  If SetupDiGetDeviceRegistryPropertyA(hAllDevices, @Data, SPDRP_DEVICEDESC,
   nil, @buf^, 100, @dwRequired) then
  begin
   s:=string(buf);
   Memo1.Lines.Add(s);
  end;
  StrDispose(buf);
 end;
 inc(dwInfo);
end;
SetupDiDestroyDeviceInfoList(hAllDevices);
SetupDiDestroyDeviceInfoList(hDev);
end;

Для того, чтобы показало все устройства - поставь вместо {4D36E96D-E325-11CE-BFC1-08002BE10318} nil, т.к. этот guide для определения модемов.

P.S. Автор не я.
Ответить с цитированием