🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8625

Re: Printing to LPT1

#8625
From: Bob Gonder
Date: Sun, 10 Oct 2004 16:54
47 lines
2502 bytes
mike wrote:

>Well it dosen't make any difference weather I try opening the printer port
>as "lpt1:" or "prn", I still don't get anything sent to the printer.
>
>So I am still at a loss as to why this does not work.


Well, since this is the native api group, let's just drop the old DOS
functions.  (Untested. Most of this is cut-n-paste, but also edited to
remove extra tests and error recovery code. The DOS_ names are because
these were conversion functions for a DOS application)

  Compile this as a Win32 console program.

#include	<windows.h>

HANDLE _fastcall DOS_OPEN_WRITE(char *filename)
{ return = CreateFile(
	filename,
	GENERIC_WRITE,
	0,
	NULL,
	OPEN_ALWAYS,

FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN|FILE_FLAG_WRITE_THROUGH,
	NULL);
}

DWORD _fastcall DOS_WRITE(HANDLE h,BYTE*b,DWORD c)
{	DWORD	written = c;
	return = WriteFile(h,b,c,&written,NULL);
}
BOOL _fastcall DOS_FLUSH(HANDLE h)
{
	return = FlushFileBuffers(h);
}
int main(void)
{	char	message[] = "This is a test\r\n1234567890\r\n\f";

	printer_handle = DOS_OPEN_WRITE("LPT1");
	DOS_WRITE( printer_handle, message, sizeof(message)-1 );
	DOS_FLUSH( printer_handle);
	CloseHandle( printer_handle );
	printer_handle = INVALID_HANDLE_VALUE;
	return 0;
}
Technical Details
Message-ID: <ahoim0p73d4lfjnvf7jpac621opq488lpa@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41673a45$1@newsgroups.borland.com> <am6gm0hctvodhsq42uao3mj83eb8vncknh@4ax.com> <41685010$1@newsgroups.borland.com> <41686651@newsgroups.borland.com> <41694039$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,facf9d1b2fa86ea6
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Printing to LPT1
Date: Sun, 10 Oct 2004 09:54:48 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <ahoim0p73d4lfjnvf7jpac621opq488lpa@4ax.com>
References: <41673a45$1@newsgroups.borland.com> <am6gm0hctvodhsq42uao3mj83eb8vncknh@4ax.com> <41685010$1@newsgroups.borland.com> <41686651@newsgroups.borland.com> <41694039$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 65.41.124.88
X-Trace: newsgroups.borland.com 1097427286 65.41.124.88 (10 Oct 2004 09:54:46 -0700)
Lines: 50
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx01.iad01.newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail