Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi LPT-Ports auflisten (https://www.delphipraxis.net/18216-lpt-ports-auflisten.html)

Borti 16. Mär 2004 07:13


LPT-Ports auflisten
 
Hallo!
ich bin grad auf der Suche nach einer Möglichkeit, wie man alle verfügbaren LPT-Ports in eine Combobox laden kann. Für die Com-Ports ist das ja kein Problem, wenn man auf die Regisitry zugreift. Aber wie mach ich das mit den LPTs?
Gruß,
Borti

Mysticus 21. Okt 2004 22:12

Re: LPT-Ports auflisten
 
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;

Borti 23. Okt 2004 16:37

Re: LPT-Ports auflisten
 
Find ich ja super, dass doch noch jemand geantwortet hat.
(es funktioniert)
Danke,
Borti


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz