ОБСУЖДЕНИЕ

ик порт

2 ответов 5,2 тыс.
Статус
Закрыто для дальнейших ответов.
Автор темы
Всем привет.
Кто знает как можно из мод Дельфи проверить наличие ик порта.
Не откажусь от примеров на С.

Благодарю за помощь.
 
Вот код определения модемов в системе:
Код:
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}');//это гуид модемов, тебе надо найти в MSDN гуид ИК-портов
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;
В твоем случае надо заменить только гуид, или для отображения всего оборудования вместо гуид поставь nil
 
Спасибо!
Все работает.
 
Статус
Закрыто для дальнейших ответов.