Correzioni

git-svn-id: svn://10.65.10.50/trunk@2658 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
alex 1996-03-01 14:00:24 +00:00
parent d8acacd092
commit c6e369fcbd
4 changed files with 658 additions and 658 deletions

View File

@ -1,313 +1,313 @@
#define STRICT #define STRICT
#ifndef _INC_WINDOWS #ifndef _INC_WINDOWS
#include <windows.h> #include <windows.h>
#endif #endif
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#pragma hdrstop #pragma hdrstop
#include "spool.h" #include "spool.h"
HDC HDCPrinter; /* Handle Device Context della Stampante */ HDC HDCPrinter; /* Handle Device Context della Stampante */
int PrintOpen; /* TRUE Stampa in esecuzione, altrimente FALSE */ int PrintOpen; /* TRUE Stampa in esecuzione, altrimente FALSE */
DOCINFO DocInfo; /* Struttura per apertura lavoro con la stampante */ DOCINFO DocInfo; /* Struttura per apertura lavoro con la stampante */
char SpoolName[32]; /* Nome dello Spool */ char SpoolName[32]; /* Nome dello Spool */
HINSTANCE hInst; HINSTANCE hInst;
int FAR PASCAL PRCLOSE(void); /* Chiusura della Stampa */ int FAR PASCAL PRCLOSE(void); /* Chiusura della Stampa */
int FAR PASCAL PROPEN(char far *NameSpool);/* Apertura della Stampa */ int FAR PASCAL PROPEN(char far *NameSpool);/* Apertura della Stampa */
int FAR PASCAL PROUT(char far *Buffer); /* Stampa una Stringa */ int FAR PASCAL PROUT(char far *Buffer); /* Stampa una Stringa */
int FAR PASCAL PRENDPAGE(void); /* Chiusura pagina */ int FAR PASCAL PRENDPAGE(void); /* Chiusura pagina */
int FAR PASCAL PRSTARTPAGE(void); /* Apertura pagina */ int FAR PASCAL PRSTARTPAGE(void); /* Apertura pagina */
HDC FAR GetHDCPrintDefault(void); /* Ritorna HDC della stampante di default */ HDC FAR GetHDCPrintDefault(void); /* Ritorna HDC della stampante di default */
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione LibMain Funzione LibMain
Descrizione Descrizione
----------- -----------
Entrata DLL Entrata DLL
Parametri Parametri
---------- ----------
HINSTANCE hInstance HINSTANCE hInstance
WORD wDataSegment WORD wDataSegment
WORD wHeapSize WORD wHeapSize
LPSTR lpszCmdLine LPSTR lpszCmdLine
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
int int
Note Note
---- ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL LibMain( HINSTANCE hInstance, WORD wDataSegment, int FAR PASCAL LibMain( HINSTANCE hInstance, WORD wDataSegment,
WORD wHeapSize, LPSTR lpszCmdLine ) WORD wHeapSize, LPSTR lpszCmdLine )
{ {
if ( wHeapSize != 0 ) UnlockData( 0 ); if ( wHeapSize != 0 ) UnlockData( 0 );
hInst = hInstance; hInst = hInstance;
HDCPrinter = NULL; HDCPrinter = NULL;
PrintOpen = TRUE; PrintOpen = TRUE;
return 1; return 1;
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione WEP Funzione WEP
Descrizione Descrizione
----------- -----------
Uscita DLL Uscita DLL
Parametri Parametri
---------- ----------
int bSystemExit int bSystemExit
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
int int
Note Note
---- ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL _export WEP ( int bSystemExit ) int FAR PASCAL _export WEP ( int bSystemExit )
{ {
PRCLOSE(); PRCLOSE();
return 1; return 1;
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione WEP Funzione WEP
Descrizione Descrizione
----------- -----------
Uscita DLL Uscita DLL
Parametri Parametri
---------- ----------
int bSystemExit int bSystemExit
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
int int
Note Note
---- ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL _export PRCLOSE() int FAR PASCAL _export PRCLOSE()
{ {
if (PrintOpen == TRUE) EndDoc(HDCPrinter); if (PrintOpen == TRUE) EndDoc(HDCPrinter);
PrintOpen = FALSE; PrintOpen = FALSE;
if (HDCPrinter != NULL) { if (HDCPrinter != NULL) {
HDCPrinter = 0; HDCPrinter = 0;
return 0; return 0;
} }
return 1; return 1;
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
* Funzione PROPEN * Funzione PROPEN
* *
* Descrizione * Descrizione
* ----------- * -----------
* Apre un lavoro con la stampante di default di Windows * Apre un lavoro con la stampante di default di Windows
* *
* Parametri * Parametri
* ---------- * ----------
* char _FAR *NameSpool Descrizione file di Spool * char _FAR *NameSpool Descrizione file di Spool
* *
* Tipo dato ritorno * Tipo dato ritorno
* ----------------- * -----------------
* int 0 OK * int 0 OK
* 1 Errore : HDC del device non valido * 1 Errore : HDC del device non valido
* 2 Errore : apertura lavoro non valido * 2 Errore : apertura lavoro non valido
* *
* Note * Note
* ---- * ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL _export PROPEN (char far * NameSpool) int FAR PASCAL _export PROPEN (char far * NameSpool)
{ {
PRCLOSE(); /* Chiude eventuale lavoro aperto */ PRCLOSE(); /* Chiude eventuale lavoro aperto */
/* Preleva HDC della stampante di default*/ /* Preleva HDC della stampante di default*/
HDCPrinter = GetHDCPrintDefault(); HDCPrinter = GetHDCPrintDefault();
if (HDCPrinter != NULL) { if (HDCPrinter != NULL) {
/* Prepara struttura DOCINFO */ /* Prepara struttura DOCINFO */
DocInfo.cbSize = sizeof(DocInfo); DocInfo.cbSize = sizeof(DocInfo);
DocInfo.lpszDocName = (char far *) SpoolName; DocInfo.lpszDocName = (char far *) SpoolName;
DocInfo.lpszOutput = NULL; DocInfo.lpszOutput = NULL;
/* Controllo che il nome dello Spool sia inferiore a 32 Byte */ /* Controllo che il nome dello Spool sia inferiore a 32 Byte */
if (strlen(NameSpool) > 31) { if (strlen(NameSpool) > 31) {
strncpy(SpoolName, NameSpool, 31); strncpy(SpoolName, NameSpool, 31);
SpoolName[31] = NULL; SpoolName[31] = NULL;
} else strcpy(SpoolName, NameSpool); } else strcpy(SpoolName, NameSpool);
/* Apre il Job */ /* Apre il Job */
if (StartDoc(HDCPrinter, (DOCINFO far *) &DocInfo) >= 0) { if (StartDoc(HDCPrinter, (DOCINFO far *) &DocInfo) >= 0) {
PrintOpen = TRUE; PrintOpen = TRUE;
return 0; /* OK */ return 0; /* OK */
} }
else { else {
PRCLOSE(); PRCLOSE();
return 2; /* Si e' verificato un errore nell' aprire il Job */ return 2; /* Si e' verificato un errore nell' aprire il Job */
} }
} }
return 1; /* HDC di Default non valido */ return 1; /* HDC di Default non valido */
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione PROUT Funzione PROUT
Descrizione Descrizione
----------- -----------
Stampa il contenuto puntato da Buffer Stampa il contenuto puntato da Buffer
Parametri Parametri
---------- ----------
char _FAR *Buffer Ptr al Buffer contenente l' output per la stampante char _FAR *Buffer Ptr al Buffer contenente l' output per la stampante
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
int 0 OK int 0 OK
1 Nessun lavoro aperto 1 Nessun lavoro aperto
2 Errore : Escape non andato a buon fine 2 Errore : Escape non andato a buon fine
Note Note
---- ----
Il contenuto del Buffer deve terminare con NULL. Il contenuto del Buffer deve terminare con NULL.
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL _export PROUT(char far *Buffer) int FAR PASCAL _export PROUT(char far *Buffer)
{ {
int RetVal; /* valore di ritorno */ int RetVal; /* valore di ritorno */
char NEAR *AllocBuffer; /* Ptr al Buffer */ char NEAR *AllocBuffer; /* Ptr al Buffer */
HLOCAL HMemLocal; /* Handle al blocco di memoria allocata localmente */ HLOCAL HMemLocal; /* Handle al blocco di memoria allocata localmente */
size_t TotLenBuffer; /* Lunghezza totale del Buffer di Input */ size_t TotLenBuffer; /* Lunghezza totale del Buffer di Input */
/* Controlla ovviamente che ci sia un lavoro aperto */ /* Controlla ovviamente che ci sia un lavoro aperto */
if (PrintOpen == TRUE) { if (PrintOpen == TRUE) {
TotLenBuffer = _fstrlen(Buffer); TotLenBuffer = _fstrlen(Buffer);
HMemLocal = LocalAlloc(LPTR, TotLenBuffer + 2); /* Alloca memoria */ HMemLocal = LocalAlloc(LPTR, TotLenBuffer + 2); /* Alloca memoria */
AllocBuffer = LocalLock(HMemLocal); /* Lock dell' Handle */ AllocBuffer = LocalLock(HMemLocal); /* Lock dell' Handle */
/* Copia Buffer in AllocBuffer in offset 2 e riempe i primi due byte con lunghezza DOCINFO */ /* Copia Buffer in AllocBuffer in offset 2 e riempe i primi due byte con lunghezza DOCINFO */
_fmemcpy((void far *) (AllocBuffer + 2), Buffer, TotLenBuffer); _fmemcpy((void far *) (AllocBuffer + 2), Buffer, TotLenBuffer);
*(size_t *) AllocBuffer = TotLenBuffer; *(size_t *) AllocBuffer = TotLenBuffer;
/* Spedisce direttamente il buffer alla stampante */ /* Spedisce direttamente il buffer alla stampante */
RetVal = Escape(HDCPrinter, PASSTHROUGH, NULL, (LPCSTR) AllocBuffer, NULL); RetVal = Escape(HDCPrinter, PASSTHROUGH, NULL, (LPCSTR) AllocBuffer, NULL);
LocalUnlock(HMemLocal); /* UNLock dell' Handle */ LocalUnlock(HMemLocal); /* UNLock dell' Handle */
LocalFree(HMemLocal); /* Libera memoria */ LocalFree(HMemLocal); /* Libera memoria */
return RetVal > 0 ? 0 : 2; /* Ritorna 0 se Escape e' andato a buon fine, altrimenti 1 */ return RetVal > 0 ? 0 : 2; /* Ritorna 0 se Escape e' andato a buon fine, altrimenti 1 */
} }
return 1; /* Ritorna 1, in quanto non e' aperto nessun lavoro */ return 1; /* Ritorna 1, in quanto non e' aperto nessun lavoro */
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione PRENDPAGE Funzione PRENDPAGE
Descrizione Descrizione
----------- -----------
Chiude una pagina Chiude una pagina
Parametri Parametri
---------- ----------
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
int 0 OK int 0 OK
1 Nessun lavoro aperto 1 Nessun lavoro aperto
Note Note
---- ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL _export PRENDPAGE() int FAR PASCAL _export PRENDPAGE()
{ {
/* Esegue EndPage se un lavoro e' attualmente in esecuzione */ /* Esegue EndPage se un lavoro e' attualmente in esecuzione */
if (PrintOpen == TRUE) return EndPage(HDCPrinter) > 0 ? 0 : 1; if (PrintOpen == TRUE) return EndPage(HDCPrinter) > 0 ? 0 : 1;
return 1; /* Nessun lavoro aperto */ return 1; /* Nessun lavoro aperto */
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione PRSTARTPAGE Funzione PRSTARTPAGE
Descrizione Descrizione
----------- -----------
Apre una pagina Apre una pagina
Parametri Parametri
---------- ----------
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
int 0 OK int 0 OK
1 Nessun lavoro aperto 1 Nessun lavoro aperto
Note Note
---- ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
int FAR PASCAL _export PRSTARTPAGE() int FAR PASCAL _export PRSTARTPAGE()
{ {
/* Esegue EndPage se un lavoro e' attualmente in esecuzione */ /* Esegue EndPage se un lavoro e' attualmente in esecuzione */
if (PrintOpen == TRUE) return (StartPage(HDCPrinter) > 0 ? 0 : 1); if (PrintOpen == TRUE) return (StartPage(HDCPrinter) > 0 ? 0 : 1);
return 1; /* Nessun lavoro aperto */ return 1; /* Nessun lavoro aperto */
} }
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Funzione GetHDCPrintDefault Funzione GetHDCPrintDefault
Descrizione Descrizione
----------- -----------
Preleva da Win.Ini nella Sezione [windows] entry [device] la Preleva da Win.Ini nella Sezione [windows] entry [device] la
stampante di Default, crea un Device Context ad essa e ritorna stampante di Default, crea un Device Context ad essa e ritorna
il suo Handle. il suo Handle.
Parametri Parametri
---------- ----------
Tipo dato ritorno Tipo dato ritorno
----------------- -----------------
HDC Handle alla stampante (se NULL : errore creazione DC) HDC Handle alla stampante (se NULL : errore creazione DC)
Note Note
---- ----
------------------------------------------------------------------*/ ------------------------------------------------------------------*/
HDC far GetHDCPrintDefault() HDC far GetHDCPrintDefault()
{ {
char ProfileDevice[100]; char ProfileDevice[100];
char far *Device, far *Driver, far *PortOut; char far *Device, far *Driver, far *PortOut;
/* Preleva in Win.Ini la Sezione [windows] entry [device] per */ /* Preleva in Win.Ini la Sezione [windows] entry [device] per */
/* stampante di default */ /* stampante di default */
GetProfileString("windows", "device", "", ProfileDevice, 100); GetProfileString("windows", "device", "", ProfileDevice, 100);
/* Compone le stringhe per identificare il device e creare il DC */ /* Compone le stringhe per identificare il device e creare il DC */
if ((Device = strtok(ProfileDevice, ",")) != NULL && if ((Device = strtok(ProfileDevice, ",")) != NULL &&
(Driver = strtok(NULL, ", ")) != NULL && (Driver = strtok(NULL, ", ")) != NULL &&
(PortOut = strtok(NULL, ", ")) != NULL) { (PortOut = strtok(NULL, ", ")) != NULL) {
#if 0 #if 0
return CreateDC(Driver, Device, PortOut, NULL); return CreateDC(Driver, Device, PortOut, NULL);
#else #else
return CreateDC("RAW", NULL, PortOut, NULL); return CreateDC("RAW", NULL, PortOut, NULL);
#endif #endif
} }
/* DC non creato, ritorna NULL */ /* DC non creato, ritorna NULL */
return NULL; return NULL;
} }
/* EOF */ /* EOF */

View File

@ -1,7 +1,7 @@
// devprn.h // devprn.h
int FAR PASCAL PRCLOSE(); /* Chiusura della Stampa */ int FAR PASCAL PRCLOSE(); /* Chiusura della Stampa */
int FAR PASCAL PROPEN(char far *NameSpool); /* Apertura della Stampa */ int FAR PASCAL PROPEN(char far *NameSpool); /* Apertura della Stampa */
int FAR PASCAL PROUT(char far *Buffer); /* Stampa una Stringa */ int FAR PASCAL PROUT(char far *Buffer); /* Stampa una Stringa */
int FAR PASCAL PRENDPAGE(); /* Chiusura pagina */ int FAR PASCAL PRENDPAGE(); /* Chiusura pagina */
int FAR PASCAL PRSTARTPAGE(); /* Apertura pagina */ int FAR PASCAL PRSTARTPAGE(); /* Apertura pagina */

View File

@ -1,316 +1,316 @@
/* FILE: spool.c */ /* FILE: spool.c */
#include "spool.h" #include "spool.h"
#include <print.h> #include <print.h>
#include <commdlg.h> #include <commdlg.h>
#include <string.h> #include <string.h>
// Play with this number // Play with this number
#define BUFSIZE 2048 #define BUFSIZE 2048
// Convenient structure for use with PASSTHROUGH escape // Convenient structure for use with PASSTHROUGH escape
typedef struct typedef struct
{ {
WORD wSize; WORD wSize;
BYTE bData[2]; // placeholder BYTE bData[2]; // placeholder
} PASSTHROUGHSTRUCT, FAR *LPPTS; } PASSTHROUGHSTRUCT, FAR *LPPTS;
BOOL bAbort; // Global printing abort flag BOOL bAbort; // Global printing abort flag
//************************************************************* //*************************************************************
// //
// _PrintFile() // _PrintFile()
// //
// Purpose: // Purpose:
// Reads a file and copies it to a printer using the // Reads a file and copies it to a printer using the
// PASSTHROUGH escape. // PASSTHROUGH escape.
// //
// Parameters: // Parameters:
// LPSTR szFile - Pointer to path/filename to print // LPSTR szFile - Pointer to path/filename to print
// HDC hPrnDC - Handle to printer DC or NULL // HDC hPrnDC - Handle to printer DC or NULL
// HGLOBAL hDevNames - Handle to DEVNAMES struct or NULL // HGLOBAL hDevNames - Handle to DEVNAMES struct or NULL
// HGLOBAL hDevMode - Handle to DEVMODE struct or NULL // HGLOBAL hDevMode - Handle to DEVMODE struct or NULL
// //
// Return: // Return:
// Returns nonzero for success or zero for failure. // Returns nonzero for success or zero for failure.
// //
// Comments: // Comments:
// hDevNames and hDevMode are only used if hPrnDC is NULL. // hDevNames and hDevMode are only used if hPrnDC is NULL.
// If both hPrnDC and hDevNames are NULL, the default // If both hPrnDC and hDevNames are NULL, the default
// printer is used. // printer is used.
// //
// History: Date Author Comment // History: Date Author Comment
// 6/03/93 JMS Created // 6/03/93 JMS Created
// //
//************************************************************* //*************************************************************
BOOL FAR PASCAL __export _PrintFile ( LPSTR szFile, BOOL FAR PASCAL __export _PrintFile ( LPSTR szFile,
HDC hPrnDC, HDC hPrnDC,
HGLOBAL hDevNames, HGLOBAL hDevNames,
HGLOBAL hDevMode ) HGLOBAL hDevMode )
{ {
int iEsc; int iEsc;
BOOL bLocalDC = TRUE; // Assume we must create a DC (hPrnDC == NULL) BOOL bLocalDC = TRUE; // Assume we must create a DC (hPrnDC == NULL)
bAbort = FALSE; // Haven't aborted yet bAbort = FALSE; // Haven't aborted yet
// Make sure we have a printer DC // Make sure we have a printer DC
if (!hPrnDC) if (!hPrnDC)
hPrnDC = GetPrinterDC(hDevNames, hDevMode); hPrnDC = GetPrinterDC(hDevNames, hDevMode);
else else
bLocalDC = FALSE; // Use passed in hPrnDC bLocalDC = FALSE; // Use passed in hPrnDC
if (!hPrnDC) if (!hPrnDC)
return FALSE; return FALSE;
// PASSTHROUGH is required. If driver doesn't support it, bail out. // PASSTHROUGH is required. If driver doesn't support it, bail out.
iEsc = PASSTHROUGH; iEsc = PASSTHROUGH;
if (!Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL)) if (!Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
{ {
bAbort = TRUE; bAbort = TRUE;
goto MSFCleanUp; goto MSFCleanUp;
} }
// If we created the DC, install an abort procedure. We don't have // If we created the DC, install an abort procedure. We don't have
// a Cancel dialog box, but the abort proc enables multitasking. // a Cancel dialog box, but the abort proc enables multitasking.
// (Use __export and compile with -GA or -GD so we don't need // (Use __export and compile with -GA or -GD so we don't need
// a MakeProcInstance.) // a MakeProcInstance.)
if (bLocalDC) if (bLocalDC)
Escape (hPrnDC, SETABORTPROC, 0, (LPSTR) PrintAbortProc, NULL); Escape (hPrnDC, SETABORTPROC, 0, (LPSTR) PrintAbortProc, NULL);
// Call EPSPRINTING if it is supported (that is, if we're on a // Call EPSPRINTING if it is supported (that is, if we're on a
// PostScript printer) to suppress downloading the pscript header. // PostScript printer) to suppress downloading the pscript header.
iEsc = EPSPRINTING; iEsc = EPSPRINTING;
if (Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL)) if (Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
{ {
iEsc = 1; // 1 == enable PASSTHROUGH (disable pscript header) iEsc = 1; // 1 == enable PASSTHROUGH (disable pscript header)
Escape(hPrnDC, EPSPRINTING, sizeof(int), (LPSTR)&iEsc, NULL); Escape(hPrnDC, EPSPRINTING, sizeof(int), (LPSTR)&iEsc, NULL);
} }
SendFile(hPrnDC, szFile); // Send file to printer (could do multiple SendFile(hPrnDC, szFile); // Send file to printer (could do multiple
// files) // files)
MSFCleanUp: // Done MSFCleanUp: // Done
if (bLocalDC) // Only delete DC if we created it if (bLocalDC) // Only delete DC if we created it
DeleteDC(hPrnDC); DeleteDC(hPrnDC);
return !bAbort; return !bAbort;
} /* _PrintFile() */ } /* _PrintFile() */
BOOL FAR PASCAL __export PrintFile(LPSTR szFile) BOOL FAR PASCAL __export PrintFile(LPSTR szFile)
{ {
return _PrintFile(szFile, NULL, NULL, NULL); return _PrintFile(szFile, NULL, NULL, NULL);
} }
VOID SendFile(HDC hPrnDC, LPSTR szFile) VOID SendFile(HDC hPrnDC, LPSTR szFile)
{ {
HGLOBAL HMem; HGLOBAL HMem;
LPPTS lpPTS; // Pointer to PASSTHROUGHSTRUCT LPPTS lpPTS; // Pointer to PASSTHROUGHSTRUCT
OFSTRUCT ofs; OFSTRUCT ofs;
HFILE hFile; HFILE hFile;
HMem = GlobalAlloc(GPTR, sizeof(WORD) + BUFSIZE); HMem = GlobalAlloc(GPTR, sizeof(WORD) + BUFSIZE);
if (HMem == NULL) if (HMem == NULL)
{ {
bAbort = TRUE; bAbort = TRUE;
return; return;
} }
lpPTS = (LPPTS)GlobalLock(HMem); lpPTS = (LPPTS)GlobalLock(HMem);
if (lpPTS == NULL) if (lpPTS == NULL)
{ {
bAbort = TRUE; bAbort = TRUE;
GlobalFree(HMem); GlobalFree(HMem);
return; return;
} }
hFile = OpenFile((LPSTR) szFile, &ofs, OF_READ); hFile = OpenFile((LPSTR) szFile, &ofs, OF_READ);
if (hFile == HFILE_ERROR) if (hFile == HFILE_ERROR)
{ {
bAbort = TRUE; // Can't open file| bAbort = TRUE; // Can't open file|
GlobalUnlock(HMem); GlobalUnlock(HMem);
GlobalFree(HMem); GlobalFree(HMem);
return; return;
} }
Escape (hPrnDC, STARTDOC, 0, "", NULL); Escape (hPrnDC, STARTDOC, 0, "", NULL);
// Loop through the file, reading a chunk at a time and passing // Loop through the file, reading a chunk at a time and passing
// it to the printer. QueryAbort calls the abort procedure, which // it to the printer. QueryAbort calls the abort procedure, which
// processes messages so we don't tie up the whole system. // processes messages so we don't tie up the whole system.
// We could skip the QueryAbort, in which case we wouldn't need // We could skip the QueryAbort, in which case we wouldn't need
// to set an abort proc at all. // to set an abort proc at all.
do { do {
if ((lpPTS->wSize=_lread(hFile, lpPTS->bData, BUFSIZE)) == HFILE_ERROR) if ((lpPTS->wSize=_lread(hFile, lpPTS->bData, BUFSIZE)) == HFILE_ERROR)
{ {
bAbort = TRUE; // error reading file bAbort = TRUE; // error reading file
break; break;
} }
Escape(hPrnDC, PASSTHROUGH, NULL, (LPSTR)lpPTS, NULL); Escape(hPrnDC, PASSTHROUGH, NULL, (LPSTR)lpPTS, NULL);
} }
while ((lpPTS->wSize == BUFSIZE) && QueryAbort(hPrnDC, 0)); while ((lpPTS->wSize == BUFSIZE) && QueryAbort(hPrnDC, 0));
if (!bAbort) if (!bAbort)
Escape(hPrnDC, ENDDOC, NULL, NULL, NULL); Escape(hPrnDC, ENDDOC, NULL, NULL, NULL);
_lclose(hFile); _lclose(hFile);
GlobalUnlock(HMem); GlobalUnlock(HMem);
GlobalFree(HMem); GlobalFree(HMem);
} /* SendFile() */ } /* SendFile() */
HDC FAR PASCAL __export GetPrinterDC(HGLOBAL hDevNames, HGLOBAL hDevMode) HDC FAR PASCAL __export GetPrinterDC(HGLOBAL hDevNames, HGLOBAL hDevMode)
{ {
HDC hdc; HDC hdc;
char szPrinter[64]; char szPrinter[64];
LPSTR szDevice=NULL, szDriver=NULL, szOutput=NULL; LPSTR szDevice=NULL, szDriver=NULL, szOutput=NULL;
LPDEVMODE lpdm; LPDEVMODE lpdm;
if (hDevNames) if (hDevNames)
{ {
LPDEVNAMES lpdn = (LPDEVNAMES) GlobalLock(hDevNames); LPDEVNAMES lpdn = (LPDEVNAMES) GlobalLock(hDevNames);
szDriver = (LPSTR) lpdn + lpdn->wDriverOffset; szDriver = (LPSTR) lpdn + lpdn->wDriverOffset;
szDevice = (LPSTR) lpdn + lpdn->wDeviceOffset; szDevice = (LPSTR) lpdn + lpdn->wDeviceOffset;
szOutput = (LPSTR) lpdn + lpdn->wOutputOffset; szOutput = (LPSTR) lpdn + lpdn->wOutputOffset;
if (hDevMode) if (hDevMode)
lpdm = (LPDEVMODE) GlobalLock(hDevMode); lpdm = (LPDEVMODE) GlobalLock(hDevMode);
} }
else else
{ // Get default printer info { // Get default printer info
GetProfileString ("windows", "device", "", szPrinter, 64); GetProfileString ("windows", "device", "", szPrinter, 64);
if (!((szDevice = strtok (szPrinter, "," )) && if (!((szDevice = strtok (szPrinter, "," )) &&
(szDriver = strtok (NULL, ", ")) && (szDriver = strtok (NULL, ", ")) &&
(szOutput = strtok (NULL, ", ")))) (szOutput = strtok (NULL, ", "))))
return NULL; // No default printer return NULL; // No default printer
lpdm = NULL; // Don't use DEVMODE with default printer lpdm = NULL; // Don't use DEVMODE with default printer
} }
hdc = CreateDC(szDriver, szDevice, szOutput, lpdm); hdc = CreateDC(szDriver, szDevice, szOutput, lpdm);
// hdc = CreateDC("RAW", NULL, szOutput, lpdm); // hdc = CreateDC("RAW", NULL, szOutput, lpdm);
if (hDevMode && lpdm) if (hDevMode && lpdm)
GlobalUnlock(hDevMode); GlobalUnlock(hDevMode);
if (hDevNames) if (hDevNames)
GlobalUnlock(hDevNames); GlobalUnlock(hDevNames);
return hdc; return hdc;
} /* GetPrinterDC() */ } /* GetPrinterDC() */
BOOL CALLBACK __export PrintAbortProc(HDC hdc, int code) BOOL CALLBACK __export PrintAbortProc(HDC hdc, int code)
{ {
MSG msg; MSG msg;
while (!bAbort && PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) while (!bAbort && PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{ {
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
return (!bAbort); return (!bAbort);
} /* PrintAbortProc() */ } /* PrintAbortProc() */
// The function that prints one line without formfeed // The function that prints one line without formfeed
BOOL FAR PASCAL __export _SpoolRow( LPSTR pData, BOOL FAR PASCAL __export _SpoolRow( LPSTR pData,
WORD cbBytes, WORD cbBytes,
HDC hPrnDC, HDC hPrnDC,
HGLOBAL hDevNames, HGLOBAL hDevNames,
HGLOBAL hDevMode ) HGLOBAL hDevMode )
{ {
int iEsc; int iEsc;
BOOL bLocalDC = TRUE; // Assume we must create a DC (hPrnDC == NULL) BOOL bLocalDC = TRUE; // Assume we must create a DC (hPrnDC == NULL)
HGLOBAL HMem; HGLOBAL HMem;
char * pOutput; char * pOutput;
HMem = GlobalAlloc(GPTR, sizeof(WORD) + cbBytes); HMem = GlobalAlloc(GPTR, sizeof(WORD) + cbBytes);
if (HMem == NULL) if (HMem == NULL)
return FALSE; return FALSE;
pOutput = (char *)GlobalLock(HMem); pOutput = (char *)GlobalLock(HMem);
if (pOutput == NULL) if (pOutput == NULL)
{ {
GlobalFree(HMem); GlobalFree(HMem);
return FALSE; return FALSE;
} }
bAbort = FALSE; // Haven't aborted yet bAbort = FALSE; // Haven't aborted yet
// Make sure we have a printer DC // Make sure we have a printer DC
if (!hPrnDC) if (!hPrnDC)
hPrnDC = GetPrinterDC(hDevNames, hDevMode); hPrnDC = GetPrinterDC(hDevNames, hDevMode);
else else
bLocalDC = FALSE; // Use passed in hPrnDC bLocalDC = FALSE; // Use passed in hPrnDC
if (!hPrnDC) if (!hPrnDC)
return FALSE; return FALSE;
if (bLocalDC) if (bLocalDC)
Escape (hPrnDC, SETABORTPROC, 0, (LPSTR) PrintAbortProc, NULL); Escape (hPrnDC, SETABORTPROC, 0, (LPSTR) PrintAbortProc, NULL);
// PASSTHROUGH is required. If driver doesn't support it, bail out. // PASSTHROUGH is required. If driver doesn't support it, bail out.
bAbort = FALSE; bAbort = FALSE;
iEsc = PASSTHROUGH; iEsc = PASSTHROUGH;
if (!Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL)) if (!Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
{ {
bAbort = TRUE; bAbort = TRUE;
goto MPLCleanUp; goto MPLCleanUp;
} }
// Call EPSPRINTING if it is supported (that is, if we're on a // Call EPSPRINTING if it is supported (that is, if we're on a
// PostScript printer) to suppress downloading the pscript header. // PostScript printer) to suppress downloading the pscript header.
iEsc = EPSPRINTING; iEsc = EPSPRINTING;
if (Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL)) if (Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
{ {
iEsc = 1; // 1 == enable PASSTHROUGH (disable pscript header) iEsc = 1; // 1 == enable PASSTHROUGH (disable pscript header)
Escape(hPrnDC, EPSPRINTING, sizeof(int), (LPSTR)&iEsc, NULL); Escape(hPrnDC, EPSPRINTING, sizeof(int), (LPSTR)&iEsc, NULL);
} }
// Start a Document // Start a Document
Escape (hPrnDC, STARTDOC, 0, "", NULL); Escape (hPrnDC, STARTDOC, 0, "", NULL);
// Put data in the buffer and send to the printer // Put data in the buffer and send to the printer
*(WORD *)pOutput = cbBytes; *(WORD *)pOutput = cbBytes;
memcpy( &(pOutput[sizeof(WORD)]), pData, cbBytes ); memcpy( &(pOutput[sizeof(WORD)]), pData, cbBytes );
if( Escape( hPrnDC, PASSTHROUGH, 0, pOutput, NULL ) <= 0 ) if( Escape( hPrnDC, PASSTHROUGH, 0, pOutput, NULL ) <= 0 )
bAbort = TRUE; bAbort = TRUE;
// End the Document // End the Document
if (!bAbort) if (!bAbort)
Escape(hPrnDC, ENDDOC, NULL, NULL, NULL); Escape(hPrnDC, ENDDOC, NULL, NULL, NULL);
MPLCleanUp: // Done MPLCleanUp: // Done
// Clean up // Clean up
if (bLocalDC) if (bLocalDC)
DeleteDC( hPrnDC ); DeleteDC( hPrnDC );
GlobalUnlock(HMem); GlobalUnlock(HMem);
GlobalFree(HMem); GlobalFree(HMem);
return !bAbort; return !bAbort;
} }
BOOL FAR PASCAL __export SpoolRow( char *pData, WORD cbBytes ) BOOL FAR PASCAL __export SpoolRow( char *pData, WORD cbBytes )
{ {
return _SpoolRow(pData, cbBytes, NULL, NULL, NULL); return _SpoolRow(pData, cbBytes, NULL, NULL, NULL);
} }
/*** EOF: spool.c ***/ /*** EOF: spool.c ***/

View File

@ -1,23 +1,23 @@
#ifndef _INC_SPOOL #ifndef _INC_SPOOL
#define _INC_SPOOL #define _INC_SPOOL
#ifndef _INC_WINDOWS #ifndef _INC_WINDOWS
#include <windows.h> #include <windows.h>
#endif #endif
// Function prototypes // Function prototypes
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
BOOL FAR PASCAL __export _PrintFile(LPSTR, HDC, HGLOBAL, HGLOBAL); BOOL FAR PASCAL __export _PrintFile(LPSTR, HDC, HGLOBAL, HGLOBAL);
BOOL FAR PASCAL __export PrintFile(LPSTR); BOOL FAR PASCAL __export PrintFile(LPSTR);
VOID SendFile(HDC, LPSTR); VOID SendFile(HDC, LPSTR);
HDC FAR PASCAL __export GetPrinterDC(HGLOBAL, HGLOBAL); HDC FAR PASCAL __export GetPrinterDC(HGLOBAL, HGLOBAL);
BOOL CALLBACK __export PrintAbortProc(HDC, int); BOOL CALLBACK __export PrintAbortProc(HDC, int);
BOOL FAR PASCAL __export _SpoolRow( LPSTR, WORD, HDC, HGLOBAL, HGLOBAL); BOOL FAR PASCAL __export _SpoolRow( LPSTR, WORD, HDC, HGLOBAL, HGLOBAL);
BOOL FAR PASCAL __export SpoolRow( LPSTR, WORD ); BOOL FAR PASCAL __export SpoolRow( LPSTR, WORD );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _INC_SPOOL */ #endif /* _INC_SPOOL */