Registriert seit: 16. Sep 2003
Ort: Gomaringen
13 Beiträge
Delphi 2009 Professional
|
Re: LPT-Ports auflisten
21. Okt 2004, 23:12
So sollte es gehen:
Delphi-Quellcode:
uses Winspool;
function GetAvailablePorts(
Ports: TStrings): Boolean;
var
NumBytesNeeded, NumStructsReturned, ii: cardinal;
PortsPtr: Pointer;
Str: String;
begin
Ports.Clear();
if (not EnumPorts(nil, 1, nil, 0, NumBytesNeeded, NumStructsReturned)) and
(GetLastError = ERROR_INSUFFICIENT_BUFFER) then
begin
GetMem(PortsPtr, NumBytesNeeded);
try
EnumPorts(nil, 1, PortsPtr, NumBytesNeeded, NumBytesNeeded, NumStructsReturned);
for ii := 0 to NumStructsReturned - 1 do
begin
Str := PPortInfo1(cardinal(PortsPtr) + ii * sizeof(TPortInfo1))^.pName;
Delete(Str, Pos(':', Str), 1000);
if Copy(Str, 1, 3) = 'LPT' then // Filter für Port-Typ
Ports.Add(Str);
end;
finally
FreeMem(PortsPtr);
end;
end;
Result := Ports.Count > 0;
end;
|
|
Zitat
|