Mail Archives: cygwin/1997/06/18/22:58:06
This is a multi-part message in MIME format.
--------------500F9F3013728473695678E2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I have a program that need to write to bytes to the printer (spooled)
It make calles to
OpenJob, StartSpoolPage, WriteSpool, EndSpoolPage, CloseJob.
I have added the neeeded prototypes to this single program. Once
it compiles it does not link. Does anyone known which dll's the
function are in.
Also I need the .def for .dll so I can link to it.
Is there a better way of write bytes to the spooled printer. What I
have is binary file that has all the control sequences for the HP4
printer and need a way to get it printer.
The program is despooler reports built on a unix box and need to
print them on the local printers.
I have attached small program that will compile and run under
Borland compiler. I need it compile under GNUWIN32 stuff.
--------------500F9F3013728473695678E2
Content-Type: image/x-xbitmap; name="winspool.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="winspool.c"
#define PRINTDRIVER
#include <windows.h>
#include <string.h>
#include <print.h>
#include <stdio.h>
#include <errno.h>
HDC print_handle;
char *print_device;
char *print_driver;
char *print_port;
void print_file(char *file_name);
int
main(int argc, char *argv[])
{
char print_info[80];
int i;
/*
* Get the default printer for the system
*/
GetProfileString("windows","device", ",,,", print_info, 80);
/*
* Parse out the device name, print driver, printer port
*/
print_device = strtok(print_info, ",");
print_driver = strtok(NULL, ", ");
print_port = strtok(NULL, ", ");
if (print_device == NULL || print_driver == NULL ||
print_port == NULL) {
fprintf(stderr, "No default printer found\n");
return 1;
}
/*
* get the printer device context for the default printer.
* This is need so that we may create/print files.
*/
print_handle = CreateDC(print_driver, print_device, print_port, NULL);
if (print_handle == NULL) {
fprintf(stderr, "Can not create context for default printer\n");
return 2;
}
/*
* Loop creating a spooled print job for each file that
* was requested to be printed.
*/
for(i=1; i < argc; i++) {
print_file(argv[i]);
}
/*
* Be a nice program and release the print context that we allocated
*/
DeleteDC(print_handle);
return 0;
}
void
print_file(char *file_name)
{
HPJOB print_job;
char buffer[1024];
FILE *input;
int size;
/*
* Create a print job to allow us to spool the output to the
* system default printer
*/
print_job = OpenJob(print_port, file_name, (HPJOB)print_handle);
/*
* Start the logical page/printjob
*/
if (StartSpoolPage(print_job) < 0) {
fprintf(stderr, "Could not create page on default printer\n");
CloseJob(print_job);
}
/*
* Open the file that we are about to spool to the printer
*/
input = fopen(file_name, "rb");
if (input == NULL) {
fprintf(stderr, "%s: %s\n", strerror(errno));
return;
}
/*
* Loop copying data from the file to printer. Keep on
* copying data till we hit the end of the file.
*/
for(;;) {
size = fread(buffer, 1, sizeof(buffer), input);
if (size <= 0)
break;
WriteSpool(print_job, buffer, size);
}
/*
* We are done with the input file. Close it
*/
fclose(input);
/*
* We have spool all the data in the file. It is now time to
* end this page/print job
*/
EndSpoolPage(print_job);
CloseJob(print_job);
}
--------------500F9F3013728473695678E2--
-
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 -