Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to get the printer port name Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
07-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
96
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to get the printer port name

Answer:

Getting the printer port name:

1   { ... }
2   
3   uses
4     printers, winspool;
5   
6   function GetCurrentPrinterHandle: THandle;
7   const
8     Defaults: TPrinterDefaults = (pDatatype: nil; pDevMode: nil; DesiredAccess:
9       PRINTER_ACCESS_USE or PRINTER_ACCESS_ADMINISTER);
10  var
11    Device, Driver, Port: array[0..255] of char;
12    hDeviceMode: THandle;
13  begin
14    Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
15    if not OpenPrinter(@Device, Result, @Defaults) then
16      RaiseLastWin32Error;
17  end;
18  
19  procedure TForm1.Button1Click(Sender: TObject);
20  
21    procedure Display(const prefix: string; S: PChar);
22    begin
23      memo1.lines.add(prefix + string(S));
24    end;
25  
26  var
27    pInfo: PPrinterInfo2;
28    bytesNeeded: DWORD;
29    hPrinter: THandle;
30    i: Integer;
31  begin
32    for i := 0 to printer.Printers.Count - 1 do
33    begin
34      Printer.PrinterIndex := i;
35      hPrinter := GetCurrentPrinterHandle;
36      try
37        GetPrinter(hPrinter, 2, nil, 0, @bytesNeeded);
38        pInfo := AllocMem(bytesNeeded);
39        try
40          GetPrinter(hPrinter, 2, pInfo, bytesNeeded, @bytesNeeded);
41          Display('ServerName: ', pInfo^.pServerName);
42          Display('PrinterName: ', pInfo^.pPrinterName);
43          Display('ShareName: ', pInfo^.pShareName);
44          Display('PortName: ', pInfo^.pPortName);
45        finally
46          FreeMem(pInfo);
47        end;
48      finally
49        ClosePrinter(hPrinter);
50      end;
51    end;
52  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC