🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.nativeapi
Article #12157

Re: Enumports

#12157
From: Adrian Hunt
Date: Fri, 22 Nov 2002 17:01
57 lines
2284 bytes
Hi

Hope this example helps... Easier then explaining!!  B)

Adrian

----

Uses
  WinSpool;

Type
  TArrayPORT_INFO_1 = Array[0..0] Of PORT_INFO_1;
  PArrayPORT_INFO_1 = ^TArrayPORT_INFO_1;

procedure LPT1Check();
Var
  apiBuffer:    PArrayPORT_INFO_1;
  lwBufferSize: LongWord;
  lwPortCount:  LongWord;
  lwIndex:      LongWord;
  sMessage:     String;
begin
  // Find required size of the buffer
  EnumPorts(Nil, 1, Nil, 0, lwBufferSize, lwPortCount);

  // Alloc and fill buffer
  apiBuffer := AllocMem(lwBufferSize);
  EnumPorts(Nil, 1, apiBuffer, lwBufferSize, lwBufferSize, lwPortCount);

  // Search returned buffer
  // Using word so must check for 0 as 0 - 1 = 4294967295  not -1!
  If lwPortCount = 0 Then
    sMessage := 'No ports installed on this system'
  Else
  Begin
    sMessage := 'LPT1: not found on this system';

    For lwIndex := 0 To lwPortCount - 1 Do
    Begin
      If UpperCase(apiBuffer[lwIndex].pName) = 'LPT1:' Then
      Begin
        sMessage := 'LPT1: exists';
        Break;
      End;    // If name
    End;    // For lwIndex
  End;    // If lwPortCount

  // Free the buffer and show result
  FreeMem(apiBuffer);
  ShowMessage(sMessage);
end;


"Carlos Azevedo" <carlos@sector.com.br> wrote:
>How to use the function Enumports to discover if the LPT1 port is install?
Technical Details
Message-ID: <3dde62dd$4@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail
References: <3dde241e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f94dd,e4085bbbbd7e21cd
X-Google-Attributes: gidf94dd,public
X-Google-ArrivalTime: 2002-11-22 09:15:50 PST
From: "Adrian Hunt" <adrianhunt@myriadworld.REMOVE_THIS.com>
Sender: "Adrian Hunt" <adrianhunt@myriadworld.REMOVE_THIS.com>
Reply-To: "Adrian Hunt" <adrianhunt@myriadworld.REMOVE_THIS.com>
Subject: Re: Enumports
Newsgroups: borland.public.delphi.nativeapi
X-User-Info: 62.64.237.48 62.64.237.48    
References:  <3dde241e@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3dde62dd$4@newsgroups.borland.com>
Date: 22 Nov 2002 09:01:17 -0800
X-Trace: newsgroups.borland.com 1037984477 207.105.83.65 (22 Nov 2002 09:01:17 -0800)
Lines: 58
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-06!sn-xit-04!supernews.com!news.maxwell.syr.edu!fu-berlin.de!news.uni-x.net!newsgroups.borland.com!not-for-mail