Aggiunta dll DevPrn cosi come arrivata da Mario
git-svn-id: svn://10.65.10.50/trunk@2576 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
4dbd405a40
commit
1ebc3c6da9
313
include/devprn.c
Executable file
313
include/devprn.c
Executable file
@ -0,0 +1,313 @@
|
|||||||
|
#define STRICT
|
||||||
|
#ifndef _INC_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#pragma hdrstop
|
||||||
|
|
||||||
|
#include "spool.h"
|
||||||
|
|
||||||
|
HDC HDCPrinter; /* Handle Device Context della Stampante */
|
||||||
|
int PrintOpen; /* TRUE Stampa in esecuzione, altrimente FALSE */
|
||||||
|
DOCINFO DocInfo; /* Struttura per apertura lavoro con la stampante */
|
||||||
|
char SpoolName[32]; /* Nome dello Spool */
|
||||||
|
HINSTANCE hInst;
|
||||||
|
|
||||||
|
int FAR PASCAL PRCLOSE(void); /* Chiusura 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 PRENDPAGE(void); /* Chiusura pagina */
|
||||||
|
int FAR PASCAL PRSTARTPAGE(void); /* Apertura pagina */
|
||||||
|
HDC FAR GetHDCPrintDefault(void); /* Ritorna HDC della stampante di default */
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione LibMain
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Entrata DLL
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
HINSTANCE hInstance
|
||||||
|
WORD wDataSegment
|
||||||
|
WORD wHeapSize
|
||||||
|
LPSTR lpszCmdLine
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
int
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL LibMain( HINSTANCE hInstance, WORD wDataSegment,
|
||||||
|
WORD wHeapSize, LPSTR lpszCmdLine )
|
||||||
|
{
|
||||||
|
if ( wHeapSize != 0 ) UnlockData( 0 );
|
||||||
|
|
||||||
|
hInst = hInstance;
|
||||||
|
HDCPrinter = NULL;
|
||||||
|
PrintOpen = TRUE;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione WEP
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Uscita DLL
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
int bSystemExit
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
int
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL _export WEP ( int bSystemExit )
|
||||||
|
{
|
||||||
|
PRCLOSE();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione WEP
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Uscita DLL
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
int bSystemExit
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
int
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL _export PRCLOSE()
|
||||||
|
{
|
||||||
|
if (PrintOpen == TRUE) EndDoc(HDCPrinter);
|
||||||
|
|
||||||
|
PrintOpen = FALSE;
|
||||||
|
|
||||||
|
if (HDCPrinter != NULL) {
|
||||||
|
HDCPrinter = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
* Funzione PROPEN
|
||||||
|
*
|
||||||
|
* Descrizione
|
||||||
|
* -----------
|
||||||
|
* Apre un lavoro con la stampante di default di Windows
|
||||||
|
*
|
||||||
|
* Parametri
|
||||||
|
* ----------
|
||||||
|
* char _FAR *NameSpool Descrizione file di Spool
|
||||||
|
*
|
||||||
|
* Tipo dato ritorno
|
||||||
|
* -----------------
|
||||||
|
* int 0 OK
|
||||||
|
* 1 Errore : HDC del device non valido
|
||||||
|
* 2 Errore : apertura lavoro non valido
|
||||||
|
*
|
||||||
|
* Note
|
||||||
|
* ----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL _export PROPEN (char far * NameSpool)
|
||||||
|
{
|
||||||
|
PRCLOSE(); /* Chiude eventuale lavoro aperto */
|
||||||
|
|
||||||
|
/* Preleva HDC della stampante di default*/
|
||||||
|
HDCPrinter = GetHDCPrintDefault();
|
||||||
|
|
||||||
|
if (HDCPrinter != NULL) {
|
||||||
|
|
||||||
|
/* Prepara struttura DOCINFO */
|
||||||
|
DocInfo.cbSize = sizeof(DocInfo);
|
||||||
|
DocInfo.lpszDocName = (char far *) SpoolName;
|
||||||
|
DocInfo.lpszOutput = NULL;
|
||||||
|
|
||||||
|
/* Controllo che il nome dello Spool sia inferiore a 32 Byte */
|
||||||
|
if (strlen(NameSpool) > 31) {
|
||||||
|
strncpy(SpoolName, NameSpool, 31);
|
||||||
|
SpoolName[31] = NULL;
|
||||||
|
} else strcpy(SpoolName, NameSpool);
|
||||||
|
|
||||||
|
/* Apre il Job */
|
||||||
|
if (StartDoc(HDCPrinter, (DOCINFO far *) &DocInfo) >= 0) {
|
||||||
|
PrintOpen = TRUE;
|
||||||
|
return 0; /* OK */
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PRCLOSE();
|
||||||
|
return 2; /* Si e' verificato un errore nell' aprire il Job */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1; /* HDC di Default non valido */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione PROUT
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Stampa il contenuto puntato da Buffer
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
char _FAR *Buffer Ptr al Buffer contenente l' output per la stampante
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
int 0 OK
|
||||||
|
1 Nessun lavoro aperto
|
||||||
|
2 Errore : Escape non andato a buon fine
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
Il contenuto del Buffer deve terminare con NULL.
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL _export PROUT(char far *Buffer)
|
||||||
|
{
|
||||||
|
int RetVal; /* valore di ritorno */
|
||||||
|
char NEAR *AllocBuffer; /* Ptr al Buffer */
|
||||||
|
HLOCAL HMemLocal; /* Handle al blocco di memoria allocata localmente */
|
||||||
|
size_t TotLenBuffer; /* Lunghezza totale del Buffer di Input */
|
||||||
|
|
||||||
|
/* Controlla ovviamente che ci sia un lavoro aperto */
|
||||||
|
if (PrintOpen == TRUE) {
|
||||||
|
|
||||||
|
TotLenBuffer = _fstrlen(Buffer);
|
||||||
|
|
||||||
|
HMemLocal = LocalAlloc(LPTR, TotLenBuffer + 2); /* Alloca memoria */
|
||||||
|
AllocBuffer = LocalLock(HMemLocal); /* Lock dell' Handle */
|
||||||
|
|
||||||
|
/* Copia Buffer in AllocBuffer in offset 2 e riempe i primi due byte con lunghezza DOCINFO */
|
||||||
|
_fmemcpy((void far *) (AllocBuffer + 2), Buffer, TotLenBuffer);
|
||||||
|
*(size_t *) AllocBuffer = TotLenBuffer;
|
||||||
|
|
||||||
|
/* Spedisce direttamente il buffer alla stampante */
|
||||||
|
RetVal = Escape(HDCPrinter, PASSTHROUGH, NULL, (LPCSTR) AllocBuffer, NULL);
|
||||||
|
|
||||||
|
LocalUnlock(HMemLocal); /* UNLock dell' Handle */
|
||||||
|
LocalFree(HMemLocal); /* Libera memoria */
|
||||||
|
|
||||||
|
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 */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione PRENDPAGE
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Chiude una pagina
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
int 0 OK
|
||||||
|
1 Nessun lavoro aperto
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL _export PRENDPAGE()
|
||||||
|
{
|
||||||
|
/* Esegue EndPage se un lavoro e' attualmente in esecuzione */
|
||||||
|
if (PrintOpen == TRUE) return EndPage(HDCPrinter) > 0 ? 0 : 1;
|
||||||
|
|
||||||
|
return 1; /* Nessun lavoro aperto */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione PRSTARTPAGE
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Apre una pagina
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
int 0 OK
|
||||||
|
1 Nessun lavoro aperto
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
int FAR PASCAL _export PRSTARTPAGE()
|
||||||
|
{
|
||||||
|
/* Esegue EndPage se un lavoro e' attualmente in esecuzione */
|
||||||
|
if (PrintOpen == TRUE) return (StartPage(HDCPrinter) > 0 ? 0 : 1);
|
||||||
|
|
||||||
|
return 1; /* Nessun lavoro aperto */
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------
|
||||||
|
Funzione GetHDCPrintDefault
|
||||||
|
|
||||||
|
Descrizione
|
||||||
|
-----------
|
||||||
|
Preleva da Win.Ini nella Sezione [windows] entry [device] la
|
||||||
|
stampante di Default, crea un Device Context ad essa e ritorna
|
||||||
|
il suo Handle.
|
||||||
|
|
||||||
|
Parametri
|
||||||
|
----------
|
||||||
|
|
||||||
|
Tipo dato ritorno
|
||||||
|
-----------------
|
||||||
|
HDC Handle alla stampante (se NULL : errore creazione DC)
|
||||||
|
|
||||||
|
Note
|
||||||
|
----
|
||||||
|
------------------------------------------------------------------*/
|
||||||
|
HDC far GetHDCPrintDefault()
|
||||||
|
{
|
||||||
|
|
||||||
|
char ProfileDevice[100];
|
||||||
|
char far *Device, far *Driver, far *PortOut;
|
||||||
|
|
||||||
|
/* Preleva in Win.Ini la Sezione [windows] entry [device] per */
|
||||||
|
/* stampante di default */
|
||||||
|
GetProfileString("windows", "device", "", ProfileDevice, 100);
|
||||||
|
|
||||||
|
/* Compone le stringhe per identificare il device e creare il DC */
|
||||||
|
if ((Device = strtok(ProfileDevice, ",")) != NULL &&
|
||||||
|
(Driver = strtok(NULL, ", ")) != NULL &&
|
||||||
|
(PortOut = strtok(NULL, ", ")) != NULL) {
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
return CreateDC(Driver, Device, PortOut, NULL);
|
||||||
|
#else
|
||||||
|
return CreateDC("RAW", NULL, PortOut, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DC non creato, ritorna NULL */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
8
include/devprn.def
Executable file
8
include/devprn.def
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
LIBRARY DEVPRN
|
||||||
|
DESCRIPTION 'Libreria di Stampa per Fox-Pro'
|
||||||
|
EXETYPE WINDOWS
|
||||||
|
CODE PRELOAD MOVEABLE DISCARDABLE
|
||||||
|
DATA PRELOAD MOVEABLE SINGLE
|
||||||
|
HEAPSIZE 1024
|
||||||
|
EXPORTS
|
||||||
|
PrintAbortProc
|
7
include/devprn.h
Executable file
7
include/devprn.h
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
// devprn.h
|
||||||
|
int FAR PASCAL PRCLOSE(); /* Chiusura 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 PRENDPAGE(); /* Chiusura pagina */
|
||||||
|
int FAR PASCAL PRSTARTPAGE(); /* Apertura pagina */
|
||||||
|
|
316
include/spool.c
Executable file
316
include/spool.c
Executable file
@ -0,0 +1,316 @@
|
|||||||
|
/* FILE: spool.c */
|
||||||
|
|
||||||
|
#include "spool.h"
|
||||||
|
#include <print.h>
|
||||||
|
#include <commdlg.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
// Play with this number
|
||||||
|
#define BUFSIZE 2048
|
||||||
|
|
||||||
|
// Convenient structure for use with PASSTHROUGH escape
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
WORD wSize;
|
||||||
|
BYTE bData[2]; // placeholder
|
||||||
|
} PASSTHROUGHSTRUCT, FAR *LPPTS;
|
||||||
|
|
||||||
|
|
||||||
|
BOOL bAbort; // Global printing abort flag
|
||||||
|
|
||||||
|
|
||||||
|
//*************************************************************
|
||||||
|
//
|
||||||
|
// _PrintFile()
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
// Reads a file and copies it to a printer using the
|
||||||
|
// PASSTHROUGH escape.
|
||||||
|
//
|
||||||
|
// Parameters:
|
||||||
|
// LPSTR szFile - Pointer to path/filename to print
|
||||||
|
// HDC hPrnDC - Handle to printer DC or NULL
|
||||||
|
// HGLOBAL hDevNames - Handle to DEVNAMES struct or NULL
|
||||||
|
// HGLOBAL hDevMode - Handle to DEVMODE struct or NULL
|
||||||
|
//
|
||||||
|
// Return:
|
||||||
|
// Returns nonzero for success or zero for failure.
|
||||||
|
//
|
||||||
|
// Comments:
|
||||||
|
// hDevNames and hDevMode are only used if hPrnDC is NULL.
|
||||||
|
// If both hPrnDC and hDevNames are NULL, the default
|
||||||
|
// printer is used.
|
||||||
|
//
|
||||||
|
// History: Date Author Comment
|
||||||
|
// 6/03/93 JMS Created
|
||||||
|
//
|
||||||
|
//*************************************************************
|
||||||
|
|
||||||
|
BOOL FAR PASCAL __export _PrintFile ( LPSTR szFile,
|
||||||
|
HDC hPrnDC,
|
||||||
|
HGLOBAL hDevNames,
|
||||||
|
HGLOBAL hDevMode )
|
||||||
|
{
|
||||||
|
int iEsc;
|
||||||
|
BOOL bLocalDC = TRUE; // Assume we must create a DC (hPrnDC == NULL)
|
||||||
|
|
||||||
|
bAbort = FALSE; // Haven't aborted yet
|
||||||
|
|
||||||
|
|
||||||
|
// Make sure we have a printer DC
|
||||||
|
|
||||||
|
if (!hPrnDC)
|
||||||
|
hPrnDC = GetPrinterDC(hDevNames, hDevMode);
|
||||||
|
else
|
||||||
|
bLocalDC = FALSE; // Use passed in hPrnDC
|
||||||
|
|
||||||
|
if (!hPrnDC)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
// PASSTHROUGH is required. If driver doesn't support it, bail out.
|
||||||
|
|
||||||
|
iEsc = PASSTHROUGH;
|
||||||
|
if (!Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
|
||||||
|
{
|
||||||
|
bAbort = TRUE;
|
||||||
|
goto MSFCleanUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we created the DC, install an abort procedure. We don't have
|
||||||
|
// a Cancel dialog box, but the abort proc enables multitasking.
|
||||||
|
// (Use __export and compile with -GA or -GD so we don't need
|
||||||
|
// a MakeProcInstance.)
|
||||||
|
|
||||||
|
if (bLocalDC)
|
||||||
|
Escape (hPrnDC, SETABORTPROC, 0, (LPSTR) PrintAbortProc, NULL);
|
||||||
|
|
||||||
|
// Call EPSPRINTING if it is supported (that is, if we're on a
|
||||||
|
// PostScript printer) to suppress downloading the pscript header.
|
||||||
|
|
||||||
|
iEsc = EPSPRINTING;
|
||||||
|
if (Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
|
||||||
|
{
|
||||||
|
iEsc = 1; // 1 == enable PASSTHROUGH (disable pscript header)
|
||||||
|
Escape(hPrnDC, EPSPRINTING, sizeof(int), (LPSTR)&iEsc, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
SendFile(hPrnDC, szFile); // Send file to printer (could do multiple
|
||||||
|
// files)
|
||||||
|
|
||||||
|
MSFCleanUp: // Done
|
||||||
|
|
||||||
|
if (bLocalDC) // Only delete DC if we created it
|
||||||
|
DeleteDC(hPrnDC);
|
||||||
|
|
||||||
|
return !bAbort;
|
||||||
|
|
||||||
|
} /* _PrintFile() */
|
||||||
|
|
||||||
|
|
||||||
|
BOOL FAR PASCAL __export PrintFile(LPSTR szFile)
|
||||||
|
{
|
||||||
|
return _PrintFile(szFile, NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID SendFile(HDC hPrnDC, LPSTR szFile)
|
||||||
|
{
|
||||||
|
HGLOBAL HMem;
|
||||||
|
LPPTS lpPTS; // Pointer to PASSTHROUGHSTRUCT
|
||||||
|
OFSTRUCT ofs;
|
||||||
|
HFILE hFile;
|
||||||
|
|
||||||
|
HMem = GlobalAlloc(GPTR, sizeof(WORD) + BUFSIZE);
|
||||||
|
if (HMem == NULL)
|
||||||
|
{
|
||||||
|
bAbort = TRUE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lpPTS = (LPPTS)GlobalLock(HMem);
|
||||||
|
if (lpPTS == NULL)
|
||||||
|
{
|
||||||
|
bAbort = TRUE;
|
||||||
|
GlobalFree(HMem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hFile = OpenFile((LPSTR) szFile, &ofs, OF_READ);
|
||||||
|
if (hFile == HFILE_ERROR)
|
||||||
|
{
|
||||||
|
bAbort = TRUE; // Can't open file|
|
||||||
|
GlobalUnlock(HMem);
|
||||||
|
GlobalFree(HMem);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Escape (hPrnDC, STARTDOC, 0, "", NULL);
|
||||||
|
|
||||||
|
// Loop through the file, reading a chunk at a time and passing
|
||||||
|
// it to the printer. QueryAbort calls the abort procedure, which
|
||||||
|
// processes messages so we don't tie up the whole system.
|
||||||
|
// We could skip the QueryAbort, in which case we wouldn't need
|
||||||
|
// to set an abort proc at all.
|
||||||
|
|
||||||
|
do {
|
||||||
|
if ((lpPTS->wSize=_lread(hFile, lpPTS->bData, BUFSIZE)) == HFILE_ERROR)
|
||||||
|
{
|
||||||
|
bAbort = TRUE; // error reading file
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Escape(hPrnDC, PASSTHROUGH, NULL, (LPSTR)lpPTS, NULL);
|
||||||
|
}
|
||||||
|
while ((lpPTS->wSize == BUFSIZE) && QueryAbort(hPrnDC, 0));
|
||||||
|
|
||||||
|
if (!bAbort)
|
||||||
|
Escape(hPrnDC, ENDDOC, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
_lclose(hFile);
|
||||||
|
GlobalUnlock(HMem);
|
||||||
|
GlobalFree(HMem);
|
||||||
|
} /* SendFile() */
|
||||||
|
|
||||||
|
HDC FAR PASCAL __export GetPrinterDC(HGLOBAL hDevNames, HGLOBAL hDevMode)
|
||||||
|
{
|
||||||
|
HDC hdc;
|
||||||
|
char szPrinter[64];
|
||||||
|
LPSTR szDevice=NULL, szDriver=NULL, szOutput=NULL;
|
||||||
|
LPDEVMODE lpdm;
|
||||||
|
|
||||||
|
if (hDevNames)
|
||||||
|
{
|
||||||
|
LPDEVNAMES lpdn = (LPDEVNAMES) GlobalLock(hDevNames);
|
||||||
|
|
||||||
|
szDriver = (LPSTR) lpdn + lpdn->wDriverOffset;
|
||||||
|
szDevice = (LPSTR) lpdn + lpdn->wDeviceOffset;
|
||||||
|
szOutput = (LPSTR) lpdn + lpdn->wOutputOffset;
|
||||||
|
|
||||||
|
if (hDevMode)
|
||||||
|
lpdm = (LPDEVMODE) GlobalLock(hDevMode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Get default printer info
|
||||||
|
GetProfileString ("windows", "device", "", szPrinter, 64);
|
||||||
|
|
||||||
|
if (!((szDevice = strtok (szPrinter, "," )) &&
|
||||||
|
(szDriver = strtok (NULL, ", ")) &&
|
||||||
|
(szOutput = strtok (NULL, ", "))))
|
||||||
|
return NULL; // No default printer
|
||||||
|
|
||||||
|
lpdm = NULL; // Don't use DEVMODE with default printer
|
||||||
|
}
|
||||||
|
|
||||||
|
hdc = CreateDC(szDriver, szDevice, szOutput, lpdm);
|
||||||
|
// hdc = CreateDC("RAW", NULL, szOutput, lpdm);
|
||||||
|
|
||||||
|
if (hDevMode && lpdm)
|
||||||
|
GlobalUnlock(hDevMode);
|
||||||
|
if (hDevNames)
|
||||||
|
GlobalUnlock(hDevNames);
|
||||||
|
|
||||||
|
return hdc;
|
||||||
|
|
||||||
|
} /* GetPrinterDC() */
|
||||||
|
|
||||||
|
|
||||||
|
BOOL CALLBACK __export PrintAbortProc(HDC hdc, int code)
|
||||||
|
{
|
||||||
|
MSG msg;
|
||||||
|
|
||||||
|
while (!bAbort && PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
||||||
|
{
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (!bAbort);
|
||||||
|
|
||||||
|
} /* PrintAbortProc() */
|
||||||
|
|
||||||
|
// The function that prints one line without formfeed
|
||||||
|
BOOL FAR PASCAL __export _SpoolRow( LPSTR pData,
|
||||||
|
WORD cbBytes,
|
||||||
|
HDC hPrnDC,
|
||||||
|
HGLOBAL hDevNames,
|
||||||
|
HGLOBAL hDevMode )
|
||||||
|
{
|
||||||
|
int iEsc;
|
||||||
|
BOOL bLocalDC = TRUE; // Assume we must create a DC (hPrnDC == NULL)
|
||||||
|
HGLOBAL HMem;
|
||||||
|
char * pOutput;
|
||||||
|
|
||||||
|
HMem = GlobalAlloc(GPTR, sizeof(WORD) + cbBytes);
|
||||||
|
if (HMem == NULL)
|
||||||
|
return FALSE;
|
||||||
|
pOutput = (char *)GlobalLock(HMem);
|
||||||
|
if (pOutput == NULL)
|
||||||
|
{
|
||||||
|
GlobalFree(HMem);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bAbort = FALSE; // Haven't aborted yet
|
||||||
|
|
||||||
|
// Make sure we have a printer DC
|
||||||
|
|
||||||
|
if (!hPrnDC)
|
||||||
|
hPrnDC = GetPrinterDC(hDevNames, hDevMode);
|
||||||
|
else
|
||||||
|
bLocalDC = FALSE; // Use passed in hPrnDC
|
||||||
|
|
||||||
|
if (!hPrnDC)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (bLocalDC)
|
||||||
|
Escape (hPrnDC, SETABORTPROC, 0, (LPSTR) PrintAbortProc, NULL);
|
||||||
|
|
||||||
|
// PASSTHROUGH is required. If driver doesn't support it, bail out.
|
||||||
|
|
||||||
|
bAbort = FALSE;
|
||||||
|
iEsc = PASSTHROUGH;
|
||||||
|
if (!Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
|
||||||
|
{
|
||||||
|
bAbort = TRUE;
|
||||||
|
goto MPLCleanUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call EPSPRINTING if it is supported (that is, if we're on a
|
||||||
|
// PostScript printer) to suppress downloading the pscript header.
|
||||||
|
|
||||||
|
iEsc = EPSPRINTING;
|
||||||
|
if (Escape(hPrnDC, QUERYESCSUPPORT, sizeof(int), (LPSTR)&iEsc, NULL))
|
||||||
|
{
|
||||||
|
iEsc = 1; // 1 == enable PASSTHROUGH (disable pscript header)
|
||||||
|
Escape(hPrnDC, EPSPRINTING, sizeof(int), (LPSTR)&iEsc, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Start a Document
|
||||||
|
Escape (hPrnDC, STARTDOC, 0, "", NULL);
|
||||||
|
|
||||||
|
// Put data in the buffer and send to the printer
|
||||||
|
*(WORD *)pOutput = cbBytes;
|
||||||
|
memcpy( &(pOutput[sizeof(WORD)]), pData, cbBytes );
|
||||||
|
if( Escape( hPrnDC, PASSTHROUGH, 0, pOutput, NULL ) <= 0 )
|
||||||
|
bAbort = TRUE;
|
||||||
|
|
||||||
|
// End the Document
|
||||||
|
if (!bAbort)
|
||||||
|
Escape(hPrnDC, ENDDOC, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
MPLCleanUp: // Done
|
||||||
|
// Clean up
|
||||||
|
if (bLocalDC)
|
||||||
|
DeleteDC( hPrnDC );
|
||||||
|
|
||||||
|
GlobalUnlock(HMem);
|
||||||
|
GlobalFree(HMem);
|
||||||
|
|
||||||
|
return !bAbort;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL FAR PASCAL __export SpoolRow( char *pData, WORD cbBytes )
|
||||||
|
{
|
||||||
|
return _SpoolRow(pData, cbBytes, NULL, NULL, NULL);
|
||||||
|
}
|
||||||
|
/*** EOF: spool.c ***/
|
23
include/spool.h
Executable file
23
include/spool.h
Executable file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef _INC_SPOOL
|
||||||
|
#define _INC_SPOOL
|
||||||
|
|
||||||
|
#ifndef _INC_WINDOWS
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Function prototypes
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
BOOL FAR PASCAL __export _PrintFile(LPSTR, HDC, HGLOBAL, HGLOBAL);
|
||||||
|
BOOL FAR PASCAL __export PrintFile(LPSTR);
|
||||||
|
VOID SendFile(HDC, LPSTR);
|
||||||
|
HDC FAR PASCAL __export GetPrinterDC(HGLOBAL, HGLOBAL);
|
||||||
|
BOOL CALLBACK __export PrintAbortProc(HDC, int);
|
||||||
|
BOOL FAR PASCAL __export _SpoolRow( LPSTR, WORD, HDC, HGLOBAL, HGLOBAL);
|
||||||
|
BOOL FAR PASCAL __export SpoolRow( LPSTR, WORD );
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* _INC_SPOOL */
|
Loading…
x
Reference in New Issue
Block a user