Mail Archives: cygwin/1998/06/01/07:35:00
If you have a printer that no longer accepts character printing from
stdio functions, you will appreciate the need for a Windows version of
the Unix lpr program, especially as an accessory to Internet programs
that use lpr under Unix to print character files.
The following lpr.c code compiles and works as a 16-bit application,
using Borland 4.52, but compiles and _doesn't_ work when compiled
using MINGW32.
Does anyone have any constructive suggestions for making the code work
under MINGW32?
========================================================================
#include <windows.h>
#include <commdlg.h>
#include <string.h>
#ifdef __WIN32__
#define HFILE_ERROR ((HFILE)(-1))
#endif
int PASCAL WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpszCmd,
int cmdShow)
{
#define PRINTER_COLUMNS 75
/* Set all structure members to zero. */
PRINTDLG pd = {0};
HANDLE hp1;
int nLines, len, nCol, nTab;
char buf[PRINTER_COLUMNS], nCh[1];
/* Initialize the necessary PRINTDLG structure members. */
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = (HWND)NULL;
pd.Flags = PD_RETURNDC;
#ifdef __WIN32__
if (HFILE_ERROR == (hp1 = _lopen(lpszCmd, OF_READ)))
#else
if (HFILE_ERROR == (hp1 = _lopen(lpszCmd, READ)))
#endif
{
MessageBox(0, lpszCmd, "Unable to open print file:", MB_OK);
return 1L;
};
/* This calls a commdlg dialog that connects to the system */
/* printer and initializes the device context, but can't be */
/* called from the Windows Dos window: */
if (PrintDlg(&pd) == 0)
{
MessageBox(0,"Unable to print", "Error", MB_OK);
_lclose(hp1);
return 0L;
};
/* Print if successful */
if (Escape(pd.hDC, STARTDOC, 8, "Article-Doc", NULL))
#if 0
MessageBox(0,"Escape call succeeded.","Message",MB_OK);
#else
;
#endif
for (nLines = 0; nLines < 120 ; nLines++)
{
for (nCol = 0; nCol < (PRINTER_COLUMNS-1) ; )
if (_hread(hp1, (LPVOID)nCh, 1UL) < 1L)
break;
else
if (nCh[0] == '\n')
break;
else
if (nCh[0] == '\r')
continue;
else
if (nCh[0] == '\t')
for (nTab = 0; (nTab < 5) && (nCol < (PRINTER_COLUMNS-1)); nTab++)
buf[nCol++] = ' ';
else
buf[nCol++] = nCh[0];
buf[nCol] = '\0';
len = nCol;
if (TextOut(pd.hDC, 50, 50 * (nLines % 60 + 1), buf, len))
#if 0
MessageBox(0,"Textout != 0", "Message", MB_OK);
#else
;
#endif
if ((nLines % 60) == 0)
Escape(pd.hDC, NEWFRAME, 0, NULL, NULL);
};
/* End the printer job: */
Escape(pd.hDC, ENDDOC, 0, NULL, NULL);
DeleteDC(pd.hDC);
if (pd.hDevMode != NULL)
GlobalFree(pd.hDevMode);
if (pd.hDevNames != NULL)
GlobalFree(pd.hDevNames);
_lclose(hp1);
return 0L;
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -