mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-26 09:42:25 +00:00
Network printers weren't showing up on at least NT4. This version
appears to be better, but Jacob has found that it still isn't perfect. Bah. [originally from svn r1589]
This commit is contained in:
parent
42cbf97a09
commit
9600d8815a
80
printing.c
80
printing.c
@ -5,46 +5,88 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "putty.h"
|
#include "putty.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Boggle. Flipping between the two branches of this #if appears to
|
||||||
|
* make all the difference as to whether network printers show up
|
||||||
|
* under PRINTER_ENUM_CONNECTIONS on NT 4. I don't pretend to
|
||||||
|
* understand this...
|
||||||
|
*/
|
||||||
|
#if 0
|
||||||
|
#define ENUM_LEVEL 5
|
||||||
|
#define ENUM_PTR LPPRINTER_INFO_5
|
||||||
|
#define ENUM_TYPE PRINTER_INFO_5
|
||||||
|
#define ENUM_MEMBER pPrinterName
|
||||||
|
#else
|
||||||
|
#define ENUM_LEVEL 1
|
||||||
|
#define ENUM_PTR LPPRINTER_INFO_1
|
||||||
|
#define ENUM_TYPE PRINTER_INFO_1
|
||||||
|
#define ENUM_MEMBER pName
|
||||||
|
#endif
|
||||||
|
|
||||||
struct printer_enum_tag {
|
struct printer_enum_tag {
|
||||||
int nprinters;
|
int nprinters;
|
||||||
LPPRINTER_INFO_5 info;
|
ENUM_PTR info;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct printer_job_tag {
|
struct printer_job_tag {
|
||||||
HANDLE hprinter;
|
HANDLE hprinter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static char *printer_add_enum(int param, char *buffer,
|
||||||
|
int offset, int *nprinters_ptr)
|
||||||
|
{
|
||||||
|
DWORD needed, nprinters;
|
||||||
|
|
||||||
|
buffer = srealloc(buffer, offset+512);
|
||||||
|
|
||||||
|
if (EnumPrinters(param, NULL, ENUM_LEVEL, buffer+offset,
|
||||||
|
512, &needed, &nprinters) == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (needed < 512)
|
||||||
|
needed = 512;
|
||||||
|
|
||||||
|
buffer = srealloc(buffer, offset+needed);
|
||||||
|
|
||||||
|
if (EnumPrinters(param, NULL, ENUM_LEVEL, buffer+offset,
|
||||||
|
needed, &needed, &nprinters) == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
*nprinters_ptr += nprinters;
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
printer_enum *printer_start_enum(int *nprinters_ptr)
|
printer_enum *printer_start_enum(int *nprinters_ptr)
|
||||||
{
|
{
|
||||||
printer_enum *ret = smalloc(sizeof(printer_enum));
|
printer_enum *ret = smalloc(sizeof(printer_enum));
|
||||||
char *buffer = NULL;
|
char *buffer = NULL, *retval;
|
||||||
DWORD needed, nprinters;
|
|
||||||
|
|
||||||
*nprinters_ptr = 0; /* default return value */
|
*nprinters_ptr = 0; /* default return value */
|
||||||
buffer = smalloc(512);
|
buffer = smalloc(512);
|
||||||
if (EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5,
|
|
||||||
buffer, 512, &needed, &nprinters) == 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (needed) {
|
retval = printer_add_enum(PRINTER_ENUM_LOCAL, buffer, 0, nprinters_ptr);
|
||||||
buffer = srealloc(buffer, needed);
|
if (!retval)
|
||||||
|
goto error;
|
||||||
|
else
|
||||||
|
buffer = retval;
|
||||||
|
retval = printer_add_enum(PRINTER_ENUM_CONNECTIONS, buffer,
|
||||||
|
sizeof(ENUM_TYPE) * *nprinters_ptr,
|
||||||
|
nprinters_ptr);
|
||||||
|
if (!retval)
|
||||||
|
goto error;
|
||||||
|
else
|
||||||
|
buffer = retval;
|
||||||
|
|
||||||
if (EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5,
|
ret->info = (ENUM_PTR)buffer;
|
||||||
(LPBYTE)buffer, needed, &needed, &nprinters) == 0)
|
ret->nprinters = *nprinters_ptr;
|
||||||
goto error;
|
|
||||||
} else {
|
|
||||||
nprinters = 0;
|
|
||||||
ret->info = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->info = (LPPRINTER_INFO_5)buffer;
|
|
||||||
ret->nprinters = *nprinters_ptr = nprinters;
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
sfree(buffer);
|
sfree(buffer);
|
||||||
sfree(ret);
|
sfree(ret);
|
||||||
|
*nprinters_ptr = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +96,7 @@ char *printer_get_name(printer_enum *pe, int i)
|
|||||||
return NULL;
|
return NULL;
|
||||||
if (i < 0 || i >= pe->nprinters)
|
if (i < 0 || i >= pe->nprinters)
|
||||||
return NULL;
|
return NULL;
|
||||||
return pe->info[i].pPrinterName;
|
return pe->info[i].ENUM_MEMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printer_finish_enum(printer_enum *pe)
|
void printer_finish_enum(printer_enum *pe)
|
||||||
|
Loading…
Reference in New Issue
Block a user