Solved

How to find legal 'PrintPort'

Posted on 1997-04-17
6
167 Views
Last Modified: 2010-04-04
Hello, I want to transfer an already preformatted PRN file (all printcodes are already in the file, so no printchars should be added) to the 'currently chosen printer'. The problem I encounter is that only printers that are connected to a (LPT) port are working fine, because I tried it the 'usual' (?) Turbo pascal way, by assiging the printerport (AssignFile(deviceptr, CharP(PrinterPort))

The problem is that when a Printer is not connected via a LPT Port but directly to a Print Queue, this will not work, because you cannot  'open the queue'.

Is there a better way to redirect the preformatted files to the printdevice?

Thanx in advance!
0
Comment
Question by:yogibear
  • 3
  • 3
6 Comments
 

Author Comment

by:yogibear
ID: 1335420
Edited text of question
0
 
LVL 1

Accepted Solution

by:
slp earned 100 total points
ID: 1335421
This situation is not going to improve in 32bit Windows environments, because, AFAIK, they won't let you open the port as a file at all.  The only solution that I can think that might work would be to access the printer via the Windows driver and use the Escape() API call with the PASSTHROUGH option, thus sending the contents of the file directly to the printer.  If this sounds like an option, let me know and I can go into more detail.

SLP

0
 

Author Comment

by:yogibear
ID: 1335422
Well... OK, This might work out....,
Please send in some details :)

Thanx up to now!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:slp
ID: 1335423
Delphi provides a Printer object that you can access when you include the "Printers" unit in your uses clause.  This object has a canvas, and the handle to that canvas is the printer's DC.  This handle can be used in the Escape() API call.  So something like the following ought to work (note that I'm doing no special error checking):

uses
  Printers ;

var
  PrnFile : file ;
  Buffer : array [0..1023] of byte ;
  RetVal : integer ;
begin
  AssignFile( PrnFile, 'MYFILE.PRN' ) ;
  Reset( PrnFile ) ;
  repeat
    BlockRead( PrnFile, Buffer, SizeOf( Buffer ), RetVal ) ;
    Escape( Printer.Canvas.Handle, PASSTHROUGH,
      SizeOf( Buffer ), @Buffer, nil ) ;
  until RetVal < SizeOf( Buffer ) ;
  Close( PrnFile ) ;
end ;  

Using Delphi File Streams rather than Pascal untyped files would also be an option, or whatever means you're used to for reading binary files.

HTH

slp


0
 

Author Comment

by:yogibear
ID: 1335424
Seems AllRight, I'll try this!

BTW, In the comment I read I only valued this question 10 points by mistake. I wanted to value this 100pts? Is there a way to give 'slp' the missing 90 points?
0
 
LVL 1

Expert Comment

by:slp
ID: 1335425
Thanks for the offer of the extra points, I'm kind of new here myself, so I don't know who or how to contact someone for "system services" yet, seems like this is mostly automated.

SLP

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now