1999-05-17 18:20:51 +02:00
|
|
|
/*
|
|
|
|
* WINSPOOL functions
|
|
|
|
*
|
|
|
|
* Copyright 1996 John Harvey
|
|
|
|
* Copyright 1998 Andreas Mohr
|
2000-05-26 01:02:46 +02:00
|
|
|
* Copyright 1999 Klaas van Gend
|
|
|
|
* Copyright 1999, 2000 Huw D M Davies
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
|
2000-11-29 19:38:24 +01:00
|
|
|
#include <stdio.h>
|
1999-05-17 18:20:51 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2000-05-26 01:02:46 +02:00
|
|
|
#include <stddef.h>
|
1999-05-17 18:20:51 +02:00
|
|
|
#include "winspool.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "winreg.h"
|
2000-09-27 00:20:14 +02:00
|
|
|
#include "wine/windef16.h"
|
2000-08-14 16:41:19 +02:00
|
|
|
#include "wine/unicode.h"
|
1999-05-17 18:20:51 +02:00
|
|
|
#include "debugtools.h"
|
1999-05-22 20:53:56 +02:00
|
|
|
#include "heap.h"
|
1999-08-15 18:34:22 +02:00
|
|
|
#include "commctrl.h"
|
2000-05-26 01:02:46 +02:00
|
|
|
#include "winnls.h"
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-08-14 16:41:19 +02:00
|
|
|
DEFAULT_DEBUG_CHANNEL(winspool);
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
typedef struct _OPENEDPRINTER
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPWSTR lpsPrinterName;
|
1999-05-17 18:20:51 +02:00
|
|
|
HANDLE hPrinter;
|
2000-05-26 01:02:46 +02:00
|
|
|
} OPENEDPRINTER, *LPOPENEDPRINTER;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-08-15 18:34:22 +02:00
|
|
|
/* The OpenedPrinter Table dynamic array */
|
|
|
|
static HDPA pOpenedPrinterDPA = NULL;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-08-15 18:34:22 +02:00
|
|
|
extern HDPA (WINAPI* WINSPOOL_DPA_CreateEx) (INT, HANDLE);
|
|
|
|
extern LPVOID (WINAPI* WINSPOOL_DPA_GetPtr) (const HDPA, INT);
|
|
|
|
extern INT (WINAPI* WINSPOOL_DPA_InsertPtr) (const HDPA, INT, LPVOID);
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-11-29 19:38:24 +01:00
|
|
|
static DWORD (WINAPI *GDI_CallDeviceCapabilities16)( LPCSTR lpszDevice, LPCSTR lpszPort,
|
|
|
|
WORD fwCapability, LPSTR lpszOutput,
|
|
|
|
LPDEVMODEA lpdm );
|
|
|
|
static INT (WINAPI *GDI_CallExtDeviceMode16)( HWND hwnd, LPDEVMODEA lpdmOutput,
|
|
|
|
LPSTR lpszDevice, LPSTR lpszPort,
|
|
|
|
LPDEVMODEA lpdmInput, LPSTR lpszProfile,
|
|
|
|
DWORD fwMode );
|
|
|
|
|
1999-05-22 20:53:56 +02:00
|
|
|
static char Printers[] =
|
2000-05-26 01:02:46 +02:00
|
|
|
"System\\CurrentControlSet\\control\\Print\\Printers\\";
|
1999-05-22 20:53:56 +02:00
|
|
|
static char Drivers[] =
|
2000-11-06 06:26:00 +01:00
|
|
|
"System\\CurrentControlSet\\control\\Print\\Environments\\%s\\Drivers\\";
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
static WCHAR DefaultEnvironmentW[] = {'W','i','n','e',0};
|
|
|
|
|
|
|
|
static WCHAR Configuration_FileW[] = {'C','o','n','f','i','g','u','r','a','t',
|
|
|
|
'i','o','n',' ','F','i','l','e',0};
|
|
|
|
static WCHAR DatatypeW[] = {'D','a','t','a','t','y','p','e',0};
|
|
|
|
static WCHAR Data_FileW[] = {'D','a','t','a',' ','F','i','l','e',0};
|
|
|
|
static WCHAR Default_DevModeW[] = {'D','e','f','a','u','l','t',' ','D','e','v',
|
|
|
|
'M','o','d','e',0};
|
|
|
|
static WCHAR Dependent_FilesW[] = {'D','e','p','e','n','d','e','n','t',' ','F',
|
|
|
|
'i','l','e','s',0};
|
|
|
|
static WCHAR DescriptionW[] = {'D','e','s','c','r','i','p','t','i','o','n',0};
|
|
|
|
static WCHAR DriverW[] = {'D','r','i','v','e','r',0};
|
|
|
|
static WCHAR Help_FileW[] = {'H','e','l','p',' ','F','i','l','e',0};
|
|
|
|
static WCHAR LocationW[] = {'L','o','c','a','t','i','o','n',0};
|
|
|
|
static WCHAR MonitorW[] = {'M','o','n','i','t','o','r',0};
|
|
|
|
static WCHAR NameW[] = {'N','a','m','e',0};
|
|
|
|
static WCHAR ParametersW[] = {'P','a','r','a','m','e','t','e','r','s',0};
|
|
|
|
static WCHAR PortW[] = {'P','o','r','t',0};
|
|
|
|
static WCHAR Print_ProcessorW[] = {'P','r','i','n','t',' ','P','r','o','c','e',
|
|
|
|
's','s','o','r',0};
|
|
|
|
static WCHAR Printer_DriverW[] = {'P','r','i','n','t','e','r',' ','D','r','i',
|
|
|
|
'v','e','r',0};
|
|
|
|
static WCHAR Separator_FileW[] = {'S','e','p','a','r','a','t','o','r',' ','F',
|
|
|
|
'i','l','e',0};
|
|
|
|
static WCHAR Share_NameW[] = {'S','h','a','r','e',' ','N','a','m','e',0};
|
|
|
|
static WCHAR WinPrintW[] = {'W','i','n','P','r','i','n','t',0};
|
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
/******************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetOpenedPrinterEntry
|
1999-05-17 18:20:51 +02:00
|
|
|
* Get the first place empty in the opened printer table
|
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static LPOPENEDPRINTER WINSPOOL_GetOpenedPrinterEntry()
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
|
|
|
int i;
|
2000-05-26 01:02:46 +02:00
|
|
|
LPOPENEDPRINTER pOpenedPrinter;
|
1999-08-15 18:34:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the opened printers' handle dynamic array.
|
|
|
|
*/
|
|
|
|
if (!pOpenedPrinterDPA)
|
|
|
|
{
|
|
|
|
pOpenedPrinterDPA = WINSPOOL_DPA_CreateEx(10, GetProcessHeap());
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
{
|
|
|
|
pOpenedPrinter = HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
2000-05-26 01:02:46 +02:00
|
|
|
sizeof(OPENEDPRINTER));
|
1999-08-15 18:34:22 +02:00
|
|
|
pOpenedPrinter->hPrinter = -1;
|
|
|
|
WINSPOOL_DPA_InsertPtr(pOpenedPrinterDPA, i, pOpenedPrinter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for a handle not yet allocated.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < pOpenedPrinterDPA->nItemCount; i++)
|
|
|
|
{
|
|
|
|
pOpenedPrinter = WINSPOOL_DPA_GetPtr(pOpenedPrinterDPA, i);
|
|
|
|
|
|
|
|
if (pOpenedPrinter->hPrinter == -1)
|
|
|
|
{
|
|
|
|
pOpenedPrinter->hPrinter = i + 1;
|
|
|
|
return pOpenedPrinter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Didn't find one, insert new element in the array.
|
|
|
|
*/
|
|
|
|
if (i == pOpenedPrinterDPA->nItemCount)
|
|
|
|
{
|
|
|
|
pOpenedPrinter = HeapAlloc(GetProcessHeap(),
|
|
|
|
HEAP_ZERO_MEMORY,
|
2000-05-26 01:02:46 +02:00
|
|
|
sizeof(OPENEDPRINTER));
|
1999-08-15 18:34:22 +02:00
|
|
|
pOpenedPrinter->hPrinter = i + 1;
|
|
|
|
WINSPOOL_DPA_InsertPtr(pOpenedPrinterDPA, i, pOpenedPrinter);
|
|
|
|
return pOpenedPrinter;
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetOpenedPrinter
|
1999-05-17 18:20:51 +02:00
|
|
|
* Get the pointer to the opened printer referred by the handle
|
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static LPOPENEDPRINTER WINSPOOL_GetOpenedPrinter(int printerHandle)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPOPENEDPRINTER pOpenedPrinter;
|
1999-08-15 18:34:22 +02:00
|
|
|
|
1999-09-03 14:20:57 +02:00
|
|
|
if(!pOpenedPrinterDPA) return NULL;
|
1999-08-15 18:34:22 +02:00
|
|
|
if((printerHandle <=0) ||
|
|
|
|
(printerHandle > (pOpenedPrinterDPA->nItemCount - 1)))
|
|
|
|
return NULL;
|
|
|
|
|
1999-09-03 14:20:57 +02:00
|
|
|
pOpenedPrinter = WINSPOOL_DPA_GetPtr(pOpenedPrinterDPA, printerHandle-1);
|
1999-08-15 18:34:22 +02:00
|
|
|
|
|
|
|
return pOpenedPrinter;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
/***********************************************************
|
|
|
|
* DEVMODEcpyAtoW
|
|
|
|
*/
|
|
|
|
static LPDEVMODEW DEVMODEcpyAtoW(DEVMODEW *dmW, const DEVMODEA *dmA)
|
|
|
|
{
|
|
|
|
BOOL Formname;
|
|
|
|
ptrdiff_t off_formname = (char *)dmA->dmFormName - (char *)dmA;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
Formname = (dmA->dmSize > off_formname);
|
|
|
|
size = dmA->dmSize + CCHDEVICENAME + (Formname ? CCHFORMNAME : 0);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, dmA->dmDeviceName, -1, dmW->dmDeviceName,
|
|
|
|
CCHDEVICENAME);
|
|
|
|
if(!Formname) {
|
|
|
|
memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion,
|
|
|
|
dmA->dmSize - CCHDEVICENAME);
|
|
|
|
} else {
|
|
|
|
memcpy(&dmW->dmSpecVersion, &dmA->dmSpecVersion,
|
|
|
|
off_formname - CCHDEVICENAME);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, dmA->dmFormName, -1, dmW->dmFormName,
|
|
|
|
CCHFORMNAME);
|
|
|
|
memcpy(&dmW->dmLogPixels, &dmA->dmLogPixels, dmA->dmSize -
|
|
|
|
(off_formname + CCHFORMNAME));
|
|
|
|
}
|
|
|
|
dmW->dmSize = size;
|
|
|
|
memcpy((char *)dmW + dmW->dmSize, (char *)dmA + dmA->dmSize,
|
|
|
|
dmA->dmDriverExtra);
|
|
|
|
return dmW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* DEVMODEdupAtoW
|
|
|
|
* Creates a unicode copy of supplied devmode on heap
|
|
|
|
*/
|
|
|
|
static LPDEVMODEW DEVMODEdupAtoW(HANDLE heap, const DEVMODEA *dmA)
|
|
|
|
{
|
|
|
|
LPDEVMODEW dmW;
|
|
|
|
DWORD size;
|
|
|
|
BOOL Formname;
|
|
|
|
ptrdiff_t off_formname;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
if(!dmA) return NULL;
|
|
|
|
|
|
|
|
off_formname = (char *)dmA->dmFormName - (char *)dmA;
|
|
|
|
Formname = (dmA->dmSize > off_formname);
|
|
|
|
size = dmA->dmSize + CCHDEVICENAME + (Formname ? CCHFORMNAME : 0);
|
|
|
|
dmW = HeapAlloc(heap, HEAP_ZERO_MEMORY, size + dmA->dmDriverExtra);
|
|
|
|
return DEVMODEcpyAtoW(dmW, dmA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* DEVMODEdupWtoA
|
|
|
|
* Creates an ascii copy of supplied devmode on heap
|
|
|
|
*/
|
|
|
|
static LPDEVMODEA DEVMODEdupWtoA(HANDLE heap, const DEVMODEW *dmW)
|
|
|
|
{
|
|
|
|
LPDEVMODEA dmA;
|
|
|
|
DWORD size;
|
|
|
|
BOOL Formname;
|
|
|
|
ptrdiff_t off_formname = (char *)dmW->dmFormName - (char *)dmW;
|
|
|
|
|
|
|
|
if(!dmW) return NULL;
|
|
|
|
Formname = (dmW->dmSize > off_formname);
|
|
|
|
size = dmW->dmSize - CCHDEVICENAME - (Formname ? CCHFORMNAME : 0);
|
|
|
|
dmA = HeapAlloc(heap, HEAP_ZERO_MEMORY, size + dmW->dmDriverExtra);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, dmW->dmDeviceName, -1, dmA->dmDeviceName,
|
|
|
|
CCHDEVICENAME, NULL, NULL);
|
|
|
|
if(!Formname) {
|
|
|
|
memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
|
|
|
|
dmW->dmSize - CCHDEVICENAME * sizeof(WCHAR));
|
|
|
|
} else {
|
|
|
|
memcpy(&dmA->dmSpecVersion, &dmW->dmSpecVersion,
|
|
|
|
off_formname - CCHDEVICENAME * sizeof(WCHAR));
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, dmW->dmFormName, -1, dmA->dmFormName,
|
|
|
|
CCHFORMNAME, NULL, NULL);
|
|
|
|
memcpy(&dmA->dmLogPixels, &dmW->dmLogPixels, dmW->dmSize -
|
|
|
|
(off_formname + CCHFORMNAME * sizeof(WCHAR)));
|
|
|
|
}
|
|
|
|
dmA->dmSize = size;
|
|
|
|
memcpy((char *)dmA + dmA->dmSize, (char *)dmW + dmW->dmSize,
|
|
|
|
dmW->dmDriverExtra);
|
|
|
|
return dmA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* PRINTER_INFO_2AtoW
|
|
|
|
* Creates a unicode copy of PRINTER_INFO_2A on heap
|
|
|
|
*/
|
|
|
|
static LPPRINTER_INFO_2W PRINTER_INFO_2AtoW(HANDLE heap, LPPRINTER_INFO_2A piA)
|
|
|
|
{
|
|
|
|
LPPRINTER_INFO_2W piW;
|
|
|
|
if(!piA) return NULL;
|
|
|
|
piW = HeapAlloc(heap, 0, sizeof(*piW));
|
|
|
|
memcpy(piW, piA, sizeof(*piW)); /* copy everything first */
|
|
|
|
piW->pServerName = HEAP_strdupAtoW(heap, 0, piA->pServerName);
|
|
|
|
piW->pPrinterName = HEAP_strdupAtoW(heap, 0, piA->pPrinterName);
|
|
|
|
piW->pShareName = HEAP_strdupAtoW(heap, 0, piA->pShareName);
|
|
|
|
piW->pPortName = HEAP_strdupAtoW(heap, 0, piA->pPortName);
|
|
|
|
piW->pDriverName = HEAP_strdupAtoW(heap, 0, piA->pDriverName);
|
|
|
|
piW->pComment = HEAP_strdupAtoW(heap, 0, piA->pComment);
|
|
|
|
piW->pLocation = HEAP_strdupAtoW(heap, 0, piA->pLocation);
|
|
|
|
piW->pDevMode = DEVMODEdupAtoW(heap, piA->pDevMode);
|
|
|
|
piW->pSepFile = HEAP_strdupAtoW(heap, 0, piA->pSepFile);
|
|
|
|
piW->pPrintProcessor = HEAP_strdupAtoW(heap, 0, piA->pPrintProcessor);
|
|
|
|
piW->pDatatype = HEAP_strdupAtoW(heap, 0, piA->pDatatype);
|
|
|
|
piW->pParameters = HEAP_strdupAtoW(heap, 0, piA->pParameters);
|
|
|
|
return piW;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
* FREE_PRINTER_INFO_2W
|
|
|
|
* Free PRINTER_INFO_2W and all strings
|
|
|
|
*/
|
|
|
|
static void FREE_PRINTER_INFO_2W(HANDLE heap, LPPRINTER_INFO_2W piW)
|
|
|
|
{
|
|
|
|
if(!piW) return;
|
|
|
|
|
|
|
|
HeapFree(heap,0,piW->pServerName);
|
|
|
|
HeapFree(heap,0,piW->pPrinterName);
|
|
|
|
HeapFree(heap,0,piW->pShareName);
|
|
|
|
HeapFree(heap,0,piW->pPortName);
|
|
|
|
HeapFree(heap,0,piW->pDriverName);
|
|
|
|
HeapFree(heap,0,piW->pComment);
|
|
|
|
HeapFree(heap,0,piW->pLocation);
|
|
|
|
HeapFree(heap,0,piW->pDevMode);
|
|
|
|
HeapFree(heap,0,piW->pSepFile);
|
|
|
|
HeapFree(heap,0,piW->pPrintProcessor);
|
|
|
|
HeapFree(heap,0,piW->pDatatype);
|
|
|
|
HeapFree(heap,0,piW->pParameters);
|
|
|
|
HeapFree(heap,0,piW);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
/******************************************************************
|
2000-06-23 17:34:52 +02:00
|
|
|
* DeviceCapabilitiesA [WINSPOOL.150 & WINSPOOL.151]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
2000-07-16 17:44:22 +02:00
|
|
|
INT WINAPI DeviceCapabilitiesA(LPCSTR pDevice,LPCSTR pPort, WORD cap,
|
1999-05-17 18:20:51 +02:00
|
|
|
LPSTR pOutput, LPDEVMODEA lpdm)
|
|
|
|
{
|
1999-09-10 16:37:29 +02:00
|
|
|
INT ret;
|
2000-11-29 19:38:24 +01:00
|
|
|
|
|
|
|
if (!GDI_CallDeviceCapabilities16)
|
|
|
|
{
|
|
|
|
GDI_CallDeviceCapabilities16 = (void*)GetProcAddress( GetModuleHandleA("gdi32"),
|
|
|
|
(LPCSTR)104 );
|
|
|
|
if (!GDI_CallDeviceCapabilities16) return -1;
|
|
|
|
}
|
2000-07-16 17:44:22 +02:00
|
|
|
ret = GDI_CallDeviceCapabilities16(pDevice, pPort, cap, pOutput, lpdm);
|
1999-09-10 16:37:29 +02:00
|
|
|
|
|
|
|
/* If DC_PAPERSIZE map POINT16s to POINTs */
|
|
|
|
if(ret != -1 && cap == DC_PAPERSIZE && pOutput) {
|
|
|
|
POINT16 *tmp = HeapAlloc( GetProcessHeap(), 0, ret * sizeof(POINT16) );
|
2000-12-13 21:03:53 +01:00
|
|
|
POINT *pt = (POINT *)pOutput;
|
1999-09-10 16:37:29 +02:00
|
|
|
INT i;
|
|
|
|
memcpy(tmp, pOutput, ret * sizeof(POINT16));
|
2000-12-13 21:03:53 +01:00
|
|
|
for(i = 0; i < ret; i++, pt++)
|
|
|
|
{
|
|
|
|
pt->x = tmp[i].x;
|
|
|
|
pt->y = tmp[i].y;
|
|
|
|
}
|
1999-09-10 16:37:29 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, tmp );
|
|
|
|
}
|
|
|
|
return ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-06-23 17:34:52 +02:00
|
|
|
* DeviceCapabilitiesW [WINSPOOL.152]
|
2000-05-26 01:02:46 +02:00
|
|
|
*
|
|
|
|
* Call DeviceCapabilitiesA since we later call 16bit stuff anyway
|
|
|
|
*
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
INT WINAPI DeviceCapabilitiesW(LPCWSTR pDevice, LPCWSTR pPort,
|
|
|
|
WORD fwCapability, LPWSTR pOutput,
|
|
|
|
const DEVMODEW *pDevMode)
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPDEVMODEA dmA = DEVMODEdupWtoA(GetProcessHeap(), pDevMode);
|
|
|
|
LPSTR pDeviceA = HEAP_strdupWtoA(GetProcessHeap(),0,pDevice);
|
|
|
|
LPSTR pPortA = HEAP_strdupWtoA(GetProcessHeap(),0,pPort);
|
|
|
|
INT ret;
|
|
|
|
|
|
|
|
if(pOutput && (fwCapability == DC_BINNAMES ||
|
|
|
|
fwCapability == DC_FILEDEPENDENCIES ||
|
|
|
|
fwCapability == DC_PAPERNAMES)) {
|
|
|
|
/* These need A -> W translation */
|
|
|
|
INT size = 0, i;
|
|
|
|
LPSTR pOutputA;
|
|
|
|
ret = DeviceCapabilitiesA(pDeviceA, pPortA, fwCapability, NULL,
|
|
|
|
dmA);
|
|
|
|
if(ret == -1)
|
|
|
|
return ret;
|
|
|
|
switch(fwCapability) {
|
|
|
|
case DC_BINNAMES:
|
|
|
|
size = 24;
|
|
|
|
break;
|
|
|
|
case DC_PAPERNAMES:
|
|
|
|
case DC_FILEDEPENDENCIES:
|
|
|
|
size = 64;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pOutputA = HeapAlloc(GetProcessHeap(), 0, size * ret);
|
|
|
|
ret = DeviceCapabilitiesA(pDeviceA, pPortA, fwCapability, pOutputA,
|
|
|
|
dmA);
|
|
|
|
for(i = 0; i < ret; i++)
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pOutputA + (i * size), -1,
|
|
|
|
pOutput + (i * size), size);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pOutputA);
|
|
|
|
} else {
|
|
|
|
ret = DeviceCapabilitiesA(pDeviceA, pPortA, fwCapability,
|
|
|
|
(LPSTR)pOutput, dmA);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(),0,pPortA);
|
|
|
|
HeapFree(GetProcessHeap(),0,pDeviceA);
|
|
|
|
HeapFree(GetProcessHeap(),0,dmA);
|
|
|
|
return ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DocumentPropertiesA [WINSPOOL.155]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
LONG WINAPI DocumentPropertiesA(HWND hWnd,HANDLE hPrinter,
|
|
|
|
LPSTR pDeviceName, LPDEVMODEA pDevModeOutput,
|
|
|
|
LPDEVMODEA pDevModeInput,DWORD fMode )
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPOPENEDPRINTER lpOpenedPrinter;
|
1999-05-17 18:20:51 +02:00
|
|
|
LPSTR lpName = pDeviceName;
|
2000-05-26 01:02:46 +02:00
|
|
|
LONG ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
|
|
|
TRACE("(%d,%d,%s,%p,%p,%ld)\n",
|
|
|
|
hWnd,hPrinter,pDeviceName,pDevModeOutput,pDevModeInput,fMode
|
|
|
|
);
|
|
|
|
|
|
|
|
if(!pDeviceName) {
|
2000-05-26 01:02:46 +02:00
|
|
|
LPWSTR lpNameW;
|
|
|
|
lpOpenedPrinter = WINSPOOL_GetOpenedPrinter(hPrinter);
|
1999-05-17 18:20:51 +02:00
|
|
|
if(!lpOpenedPrinter) {
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
lpNameW = lpOpenedPrinter->lpsPrinterName;
|
|
|
|
lpName = HEAP_strdupWtoA(GetProcessHeap(),0,lpNameW);
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
2000-11-29 19:38:24 +01:00
|
|
|
if (!GDI_CallExtDeviceMode16)
|
|
|
|
{
|
|
|
|
GDI_CallExtDeviceMode16 = (void*)GetProcAddress( GetModuleHandleA("gdi32"),
|
|
|
|
(LPCSTR)102 );
|
|
|
|
if (!GDI_CallExtDeviceMode16) return -1;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
ret = GDI_CallExtDeviceMode16(hWnd, pDevModeOutput, lpName, "LPT1:",
|
|
|
|
pDevModeInput, NULL, fMode);
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(!pDeviceName)
|
|
|
|
HeapFree(GetProcessHeap(),0,lpName);
|
|
|
|
return ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DocumentPropertiesW
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
LONG WINAPI DocumentPropertiesW(HWND hWnd, HANDLE hPrinter,
|
2000-05-26 01:02:46 +02:00
|
|
|
LPWSTR pDeviceName,
|
|
|
|
LPDEVMODEW pDevModeOutput,
|
|
|
|
LPDEVMODEW pDevModeInput, DWORD fMode)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
|
|
|
|
LPSTR pDeviceNameA = HEAP_strdupWtoA(GetProcessHeap(),0,pDeviceName);
|
|
|
|
LPDEVMODEA pDevModeInputA = DEVMODEdupWtoA(GetProcessHeap(),pDevModeInput);
|
|
|
|
LPDEVMODEA pDevModeOutputA = NULL;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
TRACE("(%d,%d,%s,%p,%p,%ld)\n",
|
1999-05-17 18:20:51 +02:00
|
|
|
hWnd,hPrinter,debugstr_w(pDeviceName),pDevModeOutput,pDevModeInput,
|
|
|
|
fMode);
|
2000-05-26 01:02:46 +02:00
|
|
|
if(pDevModeOutput) {
|
|
|
|
ret = DocumentPropertiesA(hWnd, hPrinter, pDeviceNameA, NULL, NULL, 0);
|
|
|
|
if(ret < 0) return ret;
|
|
|
|
pDevModeOutputA = HeapAlloc(GetProcessHeap(), 0, ret);
|
|
|
|
}
|
|
|
|
ret = DocumentPropertiesA(hWnd, hPrinter, pDeviceNameA, pDevModeOutputA,
|
|
|
|
pDevModeInputA, fMode);
|
|
|
|
if(pDevModeOutput) {
|
|
|
|
DEVMODEcpyAtoW(pDevModeOutput, pDevModeOutputA);
|
|
|
|
HeapFree(GetProcessHeap(),0,pDevModeOutputA);
|
|
|
|
}
|
|
|
|
if(fMode == 0 && ret > 0)
|
|
|
|
ret += (CCHDEVICENAME + CCHFORMNAME);
|
|
|
|
HeapFree(GetProcessHeap(),0,pDevModeInputA);
|
|
|
|
HeapFree(GetProcessHeap(),0,pDeviceNameA);
|
|
|
|
return ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* OpenPrinterA [WINSPOOL.196]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI OpenPrinterA(LPSTR lpPrinterName,HANDLE *phPrinter,
|
2000-05-26 01:02:46 +02:00
|
|
|
LPPRINTER_DEFAULTSA pDefault)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPWSTR lpPrinterNameW = HEAP_strdupAtoW(GetProcessHeap(),0,lpPrinterName);
|
|
|
|
PRINTER_DEFAULTSW DefaultW, *pDefaultW = NULL;
|
|
|
|
BOOL ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(pDefault) {
|
|
|
|
DefaultW.pDatatype = HEAP_strdupAtoW(GetProcessHeap(), 0,
|
|
|
|
pDefault->pDatatype);
|
|
|
|
DefaultW.pDevMode = DEVMODEdupAtoW(GetProcessHeap(),
|
|
|
|
pDefault->pDevMode);
|
|
|
|
DefaultW.DesiredAccess = pDefault->DesiredAccess;
|
|
|
|
pDefaultW = &DefaultW;
|
|
|
|
}
|
|
|
|
ret = OpenPrinterW(lpPrinterNameW, phPrinter, pDefaultW);
|
|
|
|
if(pDefault) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, DefaultW.pDatatype);
|
|
|
|
HeapFree(GetProcessHeap(), 0, DefaultW.pDevMode);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpPrinterNameW);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* OpenPrinterW [WINSPOOL.197]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI OpenPrinterW(LPWSTR lpPrinterName,HANDLE *phPrinter,
|
|
|
|
LPPRINTER_DEFAULTSW pDefault)
|
|
|
|
{
|
|
|
|
LPOPENEDPRINTER lpOpenedPrinter;
|
1999-09-10 16:37:29 +02:00
|
|
|
HKEY hkeyPrinters, hkeyPrinter;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-02-25 22:38:17 +01:00
|
|
|
if (!lpPrinterName) {
|
|
|
|
WARN("(printerName: NULL, pDefault %p Ret: False\n", pDefault);
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
TRACE("(printerName: %s, pDefault %p)\n", debugstr_w(lpPrinterName),
|
|
|
|
pDefault);
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-09-10 16:37:29 +02:00
|
|
|
/* Check Printer exists */
|
|
|
|
if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't create Printers key\n");
|
|
|
|
SetLastError(ERROR_FILE_NOT_FOUND); /* ?? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(RegOpenKeyW(hkeyPrinters, lpPrinterName, &hkeyPrinter)
|
1999-09-10 16:37:29 +02:00
|
|
|
!= ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
WARN("Can't find printer %s in registry\n", debugstr_w(lpPrinterName));
|
1999-09-10 16:37:29 +02:00
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-09-10 16:37:29 +02:00
|
|
|
if(!phPrinter) /* This seems to be what win95 does anyway */
|
|
|
|
return TRUE;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-09-10 16:37:29 +02:00
|
|
|
/* Get a place in the opened printer buffer*/
|
2000-05-26 01:02:46 +02:00
|
|
|
lpOpenedPrinter = WINSPOOL_GetOpenedPrinterEntry();
|
1999-09-10 16:37:29 +02:00
|
|
|
if(!lpOpenedPrinter) {
|
|
|
|
ERR("Can't allocate printer slot\n");
|
|
|
|
SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-09-10 16:37:29 +02:00
|
|
|
/* Get the name of the printer */
|
2000-11-13 05:16:05 +01:00
|
|
|
lpOpenedPrinter->lpsPrinterName = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
(strlenW(lpPrinterName)+1)*sizeof(WCHAR) );
|
|
|
|
strcpyW( lpOpenedPrinter->lpsPrinterName, lpPrinterName );
|
1999-09-10 16:37:29 +02:00
|
|
|
|
|
|
|
/* Get the unique handle of the printer*/
|
|
|
|
*phPrinter = lpOpenedPrinter->hPrinter;
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if (pDefault != NULL)
|
|
|
|
FIXME("Not handling pDefault\n");
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
return TRUE;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddMonitorA [WINSPOOL.107]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
1999-09-04 16:30:33 +02:00
|
|
|
BOOL WINAPI AddMonitorA(LPSTR pName, DWORD Level, LPBYTE pMonitors)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
|
|
|
FIXME("(%s,%lx,%p):stub!\n", pName, Level, pMonitors);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DeletePrinterDriverA [WINSPOOL.146]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI
|
|
|
|
DeletePrinterDriverA (LPSTR pName, LPSTR pEnvironment, LPSTR pDriverName)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
|
|
|
|
debugstr_a(pDriverName));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DeleteMonitorA [WINSPOOL.135]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI
|
|
|
|
DeleteMonitorA (LPSTR pName, LPSTR pEnvironment, LPSTR pMonitorName)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%s,%s):stub\n",debugstr_a(pName),debugstr_a(pEnvironment),
|
|
|
|
debugstr_a(pMonitorName));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DeletePortA [WINSPOOL.137]
|
1999-05-17 18:20:51 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI
|
|
|
|
DeletePortA (LPSTR pName, HWND hWnd, LPSTR pPortName)
|
|
|
|
{
|
|
|
|
FIXME("(%s,0x%08x,%s):stub\n",debugstr_a(pName),hWnd,
|
|
|
|
debugstr_a(pPortName));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetPrinterW [WINSPOOL.214]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI
|
|
|
|
SetPrinterW(
|
|
|
|
HANDLE hPrinter,
|
|
|
|
DWORD Level,
|
|
|
|
LPBYTE pPrinter,
|
|
|
|
DWORD Command) {
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
FIXME("():stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* WritePrinter [WINSPOOL.223]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI
|
|
|
|
WritePrinter(
|
|
|
|
HANDLE hPrinter,
|
|
|
|
LPVOID pBuf,
|
|
|
|
DWORD cbBuf,
|
|
|
|
LPDWORD pcWritten) {
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
FIXME("():stub\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddFormA [WINSPOOL.103]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI AddFormA(HANDLE hPrinter, DWORD Level, LPBYTE pForm)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%p): stub\n", hPrinter, Level, pForm);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddFormW [WINSPOOL.104]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI AddFormW(HANDLE hPrinter, DWORD Level, LPBYTE pForm)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%p): stub\n", hPrinter, Level, pForm);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddJobA [WINSPOOL.105]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI AddJobA(HANDLE hPrinter, DWORD Level, LPBYTE pData,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%p,%ld,%p): stub\n", hPrinter, Level, pData, cbBuf,
|
|
|
|
pcbNeeded);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddJobW [WINSPOOL.106]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI AddJobW(HANDLE hPrinter, DWORD Level, LPBYTE pData, DWORD cbBuf,
|
|
|
|
LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%p,%ld,%p): stub\n", hPrinter, Level, pData, cbBuf,
|
|
|
|
pcbNeeded);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-11-06 06:26:00 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* WINSPOOL_OpenDriverReg [internal]
|
|
|
|
*
|
|
|
|
* opens the registry for the printer drivers depending on the given input
|
|
|
|
* variable pEnvironment
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* the opened hkey on success
|
|
|
|
* NULL on error
|
|
|
|
*/
|
|
|
|
static HKEY WINSPOOL_OpenDriverReg( LPVOID pEnvironment, BOOL unicode)
|
|
|
|
{ HKEY retval;
|
|
|
|
LPSTR lpKey, p = NULL;
|
|
|
|
|
|
|
|
TRACE("%s\n",
|
|
|
|
(unicode) ? debugstr_w(pEnvironment) : debugstr_a(pEnvironment));
|
|
|
|
|
|
|
|
if(pEnvironment)
|
|
|
|
p = (unicode) ? HEAP_strdupWtoA( GetProcessHeap(), 0, pEnvironment) :
|
|
|
|
pEnvironment;
|
|
|
|
else {
|
|
|
|
OSVERSIONINFOA ver;
|
|
|
|
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
|
|
|
|
|
|
|
|
if(!GetVersionExA( &ver))
|
2000-12-13 21:03:53 +01:00
|
|
|
return 0;
|
2000-11-06 06:26:00 +01:00
|
|
|
|
|
|
|
switch (ver.dwPlatformId) {
|
|
|
|
case VER_PLATFORM_WIN32s:
|
2000-12-13 21:03:53 +01:00
|
|
|
return 0;
|
2000-11-06 06:26:00 +01:00
|
|
|
case VER_PLATFORM_WIN32_NT:
|
|
|
|
p = "Windows NT x86";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
p = "Windows 4.0";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
TRACE("set environment to %s\n", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
lpKey = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
strlen(p) + strlen(Drivers));
|
2000-11-29 19:38:24 +01:00
|
|
|
sprintf( lpKey, Drivers, p);
|
2000-11-06 06:26:00 +01:00
|
|
|
|
|
|
|
TRACE("%s\n", lpKey);
|
|
|
|
|
2000-11-10 02:04:29 +01:00
|
|
|
if(RegCreateKeyA(HKEY_LOCAL_MACHINE, lpKey, &retval) !=
|
2000-11-06 06:26:00 +01:00
|
|
|
ERROR_SUCCESS)
|
2000-12-13 21:03:53 +01:00
|
|
|
retval = 0;
|
2000-11-06 06:26:00 +01:00
|
|
|
|
|
|
|
if(pEnvironment && unicode)
|
|
|
|
HeapFree( GetProcessHeap(), 0, p);
|
|
|
|
HeapFree( GetProcessHeap(), 0, lpKey);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
/*****************************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* AddPrinterW [WINSPOOL.122]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
HANDLE WINAPI AddPrinterW(LPWSTR pName, DWORD Level, LPBYTE pPrinter)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
PRINTER_INFO_2W *pi = (PRINTER_INFO_2W *) pPrinter;
|
|
|
|
LPDEVMODEA dmA;
|
|
|
|
LPDEVMODEW dmW;
|
1999-05-22 20:53:56 +02:00
|
|
|
HANDLE retval;
|
|
|
|
HKEY hkeyPrinter, hkeyPrinters, hkeyDriver, hkeyDrivers;
|
2000-05-26 01:02:46 +02:00
|
|
|
LONG size;
|
1999-05-22 20:53:56 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
TRACE("(%s,%ld,%p)\n", debugstr_w(pName), Level, pPrinter);
|
1999-05-22 20:53:56 +02:00
|
|
|
|
|
|
|
if(pName != NULL) {
|
2000-05-26 01:02:46 +02:00
|
|
|
FIXME("pName = %s - unsupported\n", debugstr_w(pName));
|
1999-05-22 20:53:56 +02:00
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(Level != 2) {
|
|
|
|
WARN("Level = %ld\n", Level);
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!pPrinter) {
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't create Printers key\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
if(RegOpenKeyW(hkeyPrinters, pi->pPrinterName, &hkeyPrinter) ==
|
1999-05-22 20:53:56 +02:00
|
|
|
ERROR_SUCCESS) {
|
|
|
|
SetLastError(ERROR_PRINTER_ALREADY_EXISTS);
|
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-11-06 06:26:00 +01:00
|
|
|
hkeyDrivers = WINSPOOL_OpenDriverReg( NULL, TRUE);
|
|
|
|
if(!hkeyDrivers) {
|
1999-05-22 20:53:56 +02:00
|
|
|
ERR("Can't create Drivers key\n");
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
if(RegOpenKeyW(hkeyDrivers, pi->pDriverName, &hkeyDriver) !=
|
1999-05-22 20:53:56 +02:00
|
|
|
ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
WARN("Can't find driver %s\n", debugstr_w(pi->pDriverName));
|
1999-05-22 20:53:56 +02:00
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
SetLastError(ERROR_UNKNOWN_PRINTER_DRIVER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyDriver);
|
|
|
|
RegCloseKey(hkeyDrivers);
|
2000-05-26 01:02:46 +02:00
|
|
|
|
|
|
|
if(lstrcmpiW(pi->pPrintProcessor, WinPrintW)) { /* FIXME */
|
|
|
|
WARN("Can't find processor %s\n", debugstr_w(pi->pPrintProcessor));
|
1999-05-22 20:53:56 +02:00
|
|
|
SetLastError(ERROR_UNKNOWN_PRINTPROCESSOR);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return 0;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
|
|
|
|
/* See if we can load the driver. We may need the devmode structure anyway
|
|
|
|
*/
|
|
|
|
size = DocumentPropertiesW(0, -1, pi->pPrinterName, NULL, NULL, 0);
|
|
|
|
if(size < 0) {
|
|
|
|
WARN("DocumentProperties fails\n");
|
|
|
|
SetLastError(ERROR_UNKNOWN_PRINTER_DRIVER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(pi->pDevMode) {
|
|
|
|
dmW = pi->pDevMode;
|
|
|
|
} else {
|
|
|
|
dmW = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
DocumentPropertiesW(0, -1, pi->pPrinterName, dmW, NULL, DM_OUT_BUFFER);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RegCreateKeyW(hkeyPrinters, pi->pPrinterName, &hkeyPrinter) !=
|
1999-05-22 20:53:56 +02:00
|
|
|
ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
WARN("Can't create printer %s\n", debugstr_w(pi->pPrinterName));
|
1999-05-22 20:53:56 +02:00
|
|
|
SetLastError(ERROR_INVALID_PRINTER_NAME);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
2000-05-26 01:02:46 +02:00
|
|
|
if(!pi->pDevMode)
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
1999-05-22 20:53:56 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RegSetValueExA(hkeyPrinter, "Attributes", 0, REG_DWORD,
|
2000-05-26 01:02:46 +02:00
|
|
|
(LPBYTE)&pi->Attributes, sizeof(DWORD));
|
|
|
|
RegSetValueExW(hkeyPrinter, DatatypeW, 0, REG_SZ, (LPBYTE)pi->pDatatype,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* Write DEVMODEA not DEVMODEW into reg. This is what win9x does
|
|
|
|
and we support these drivers. NT writes DEVMODEW so somehow
|
|
|
|
we'll need to distinguish between these when we support NT
|
|
|
|
drivers */
|
|
|
|
dmA = DEVMODEdupWtoA(GetProcessHeap(), dmW);
|
|
|
|
RegSetValueExA(hkeyPrinter, "Default DevMode", 0, REG_BINARY, (LPBYTE)dmA,
|
|
|
|
dmA->dmSize + dmA->dmDriverExtra);
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmA);
|
|
|
|
if(!pi->pDevMode)
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmW);
|
|
|
|
RegSetValueExW(hkeyPrinter, DescriptionW, 0, REG_SZ, (LPBYTE)pi->pComment,
|
|
|
|
0);
|
|
|
|
RegSetValueExW(hkeyPrinter, LocationW, 0, REG_SZ, (LPBYTE)pi->pLocation,
|
1999-05-22 20:53:56 +02:00
|
|
|
0);
|
2000-05-26 01:02:46 +02:00
|
|
|
RegSetValueExW(hkeyPrinter, NameW, 0, REG_SZ, (LPBYTE)pi->pPrinterName, 0);
|
|
|
|
RegSetValueExW(hkeyPrinter, ParametersW, 0, REG_SZ,
|
|
|
|
(LPBYTE)pi->pParameters, 0);
|
|
|
|
RegSetValueExW(hkeyPrinter, PortW, 0, REG_SZ, (LPBYTE)pi->pPortName, 0);
|
|
|
|
RegSetValueExW(hkeyPrinter, Print_ProcessorW, 0, REG_SZ,
|
|
|
|
(LPBYTE)pi->pPrintProcessor, 0);
|
|
|
|
RegSetValueExW(hkeyPrinter, Printer_DriverW, 0, REG_SZ,
|
|
|
|
(LPBYTE)pi->pDriverName, 0);
|
1999-05-22 20:53:56 +02:00
|
|
|
RegSetValueExA(hkeyPrinter, "Priority", 0, REG_DWORD,
|
2000-05-26 01:02:46 +02:00
|
|
|
(LPBYTE)&pi->Priority, sizeof(DWORD));
|
|
|
|
RegSetValueExW(hkeyPrinter, Separator_FileW, 0, REG_SZ,
|
|
|
|
(LPBYTE)pi->pSepFile, 0);
|
|
|
|
RegSetValueExW(hkeyPrinter, Share_NameW, 0, REG_SZ, (LPBYTE)pi->pShareName,
|
|
|
|
0);
|
|
|
|
RegSetValueExA(hkeyPrinter, "StartTime", 0, REG_DWORD,
|
|
|
|
(LPBYTE)&pi->StartTime, sizeof(DWORD));
|
1999-05-22 20:53:56 +02:00
|
|
|
RegSetValueExA(hkeyPrinter, "Status", 0, REG_DWORD,
|
2000-05-26 01:02:46 +02:00
|
|
|
(LPBYTE)&pi->Status, sizeof(DWORD));
|
|
|
|
RegSetValueExA(hkeyPrinter, "UntilTime", 0, REG_DWORD,
|
|
|
|
(LPBYTE)&pi->UntilTime, sizeof(DWORD));
|
1999-05-22 20:53:56 +02:00
|
|
|
|
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
2000-05-26 01:02:46 +02:00
|
|
|
if(!OpenPrinterW(pi->pPrinterName, &retval, NULL)) {
|
1999-05-22 20:53:56 +02:00
|
|
|
ERR("OpenPrinter failing\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return retval;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* AddPrinterA [WINSPOOL.117]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
HANDLE WINAPI AddPrinterA(LPSTR pName, DWORD Level, LPBYTE pPrinter)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
WCHAR *pNameW;
|
|
|
|
PRINTER_INFO_2W *piW;
|
|
|
|
PRINTER_INFO_2A *piA = (PRINTER_INFO_2A*)pPrinter;
|
|
|
|
HANDLE ret;
|
|
|
|
|
|
|
|
TRACE("(%s,%ld,%p): stub\n", debugstr_a(pName), Level, pPrinter);
|
|
|
|
if(Level != 2) {
|
|
|
|
WARN("Level = %ld\n", Level);
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
pNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, pName);
|
|
|
|
piW = PRINTER_INFO_2AtoW(GetProcessHeap(), piA);
|
|
|
|
|
|
|
|
ret = AddPrinterW(pNameW, Level, (LPBYTE)piW);
|
|
|
|
|
|
|
|
FREE_PRINTER_INFO_2W(GetProcessHeap(), piW);
|
|
|
|
HeapFree(GetProcessHeap(),0,pNameW);
|
|
|
|
return ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ClosePrinter [WINSPOOL.126]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ClosePrinter(HANDLE hPrinter)
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPOPENEDPRINTER lpOpenedPrinter;
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-08-15 18:34:22 +02:00
|
|
|
TRACE("Handle %d\n", hPrinter);
|
|
|
|
|
|
|
|
if (!pOpenedPrinterDPA)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((hPrinter != -1) && (hPrinter < (pOpenedPrinterDPA->nItemCount - 1)))
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
lpOpenedPrinter = WINSPOOL_GetOpenedPrinter(hPrinter);
|
1999-05-17 18:20:51 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpOpenedPrinter->lpsPrinterName);
|
|
|
|
lpOpenedPrinter->lpsPrinterName = NULL;
|
|
|
|
lpOpenedPrinter->hPrinter = -1;
|
1999-08-15 18:34:22 +02:00
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DeleteFormA [WINSPOOL.133]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteFormA(HANDLE hPrinter, LPSTR pFormName)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%s): stub\n", hPrinter, pFormName);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DeleteFormW [WINSPOOL.134]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DeleteFormW(HANDLE hPrinter, LPWSTR pFormName)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%s): stub\n", hPrinter, debugstr_w(pFormName));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* DeletePrinter [WINSPOOL.143]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI DeletePrinter(HANDLE hPrinter)
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
LPWSTR lpNameW;
|
|
|
|
HKEY hkeyPrinters;
|
|
|
|
|
|
|
|
LPOPENEDPRINTER lpOpenedPrinter = WINSPOOL_GetOpenedPrinter(hPrinter);
|
|
|
|
if(!lpOpenedPrinter) {
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
lpNameW = lpOpenedPrinter->lpsPrinterName;
|
|
|
|
if(RegOpenKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't open Printers key\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This should use a recursive delete see Q142491 or SHDeleteKey */
|
|
|
|
if(RegDeleteKeyW(hkeyPrinters, lpNameW) == ERROR_SUCCESS) {
|
|
|
|
SetLastError(ERROR_PRINTER_NOT_FOUND); /* ?? */
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClosePrinter(hPrinter);
|
|
|
|
return TRUE;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetPrinterA [WINSPOOL.211]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
|
|
|
|
DWORD Command)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%p,%ld): stub\n",hPrinter,Level,pPrinter,Command);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetJobA [WINSPOOL.209]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetJobA(HANDLE hPrinter, DWORD JobId, DWORD Level,
|
|
|
|
LPBYTE pJob, DWORD Command)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%ld,%p,%ld): stub\n",hPrinter,JobId,Level,pJob,
|
|
|
|
Command);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetJobW [WINSPOOL.210]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetJobW(HANDLE hPrinter, DWORD JobId, DWORD Level,
|
|
|
|
LPBYTE pJob, DWORD Command)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%ld,%ld,%p,%ld): stub\n",hPrinter,JobId,Level,pJob,
|
|
|
|
Command);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* GetFormA [WINSPOOL.181]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetFormA(HANDLE hPrinter, LPSTR pFormName, DWORD Level,
|
|
|
|
LPBYTE pForm, DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%s,%ld,%p,%ld,%p): stub\n",hPrinter,pFormName,
|
|
|
|
Level,pForm,cbBuf,pcbNeeded);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* GetFormW [WINSPOOL.182]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetFormW(HANDLE hPrinter, LPWSTR pFormName, DWORD Level,
|
|
|
|
LPBYTE pForm, DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%s,%ld,%p,%ld,%p): stub\n",hPrinter,
|
|
|
|
debugstr_w(pFormName),Level,pForm,cbBuf,pcbNeeded);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetFormA [WINSPOOL.207]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetFormA(HANDLE hPrinter, LPSTR pFormName, DWORD Level,
|
|
|
|
LPBYTE pForm)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%s,%ld,%p): stub\n",hPrinter,pFormName,Level,pForm);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* SetFormW [WINSPOOL.208]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI SetFormW(HANDLE hPrinter, LPWSTR pFormName, DWORD Level,
|
|
|
|
LPBYTE pForm)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%p,%ld,%p): stub\n",hPrinter,pFormName,Level,pForm);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ReadPrinter [WINSPOOL.202]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ReadPrinter(HANDLE hPrinter, LPVOID pBuf, DWORD cbBuf,
|
|
|
|
LPDWORD pNoBytesRead)
|
|
|
|
{
|
|
|
|
FIXME("(%d,%p,%ld,%p): stub\n",hPrinter,pBuf,cbBuf,pNoBytesRead);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ResetPrinterA [WINSPOOL.203]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ResetPrinterA(HANDLE hPrinter, LPPRINTER_DEFAULTSA pDefault)
|
|
|
|
{
|
|
|
|
FIXME("(%d, %p): stub\n", hPrinter, pDefault);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* ResetPrinterW [WINSPOOL.204]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI ResetPrinterW(HANDLE hPrinter, LPPRINTER_DEFAULTSW pDefault)
|
|
|
|
{
|
|
|
|
FIXME("(%d, %p): stub\n", hPrinter, pDefault);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* WINSPOOL_GetDWORDFromReg
|
|
|
|
*
|
|
|
|
* Return DWORD associated with ValueName from hkey.
|
|
|
|
*/
|
|
|
|
static DWORD WINSPOOL_GetDWORDFromReg(HKEY hkey, LPCSTR ValueName)
|
|
|
|
{
|
|
|
|
DWORD sz = sizeof(DWORD), type, value = 0;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
ret = RegQueryValueExA(hkey, ValueName, 0, &type, (LPBYTE)&value, &sz);
|
|
|
|
|
|
|
|
if(ret != ERROR_SUCCESS) {
|
|
|
|
WARN("Got ret = %ld on name %s\n", ret, ValueName);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(type != REG_DWORD) {
|
|
|
|
ERR("Got type %ld\n", type);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
1999-07-10 13:58:50 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetStringFromReg
|
1999-07-10 13:58:50 +02:00
|
|
|
*
|
2000-05-26 01:02:46 +02:00
|
|
|
* Get ValueName from hkey storing result in ptr. buflen is space left in ptr
|
|
|
|
* String is stored either as unicode or ascii.
|
|
|
|
* Bit of a hack here to get the ValueName if we want ascii.
|
1999-07-10 13:58:50 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_GetStringFromReg(HKEY hkey, LPCWSTR ValueName, LPBYTE ptr,
|
|
|
|
DWORD buflen, DWORD *needed,
|
|
|
|
BOOL unicode)
|
1999-07-10 13:58:50 +02:00
|
|
|
{
|
|
|
|
DWORD sz = buflen, type;
|
|
|
|
LONG ret;
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(unicode)
|
|
|
|
ret = RegQueryValueExW(hkey, ValueName, 0, &type, ptr, &sz);
|
|
|
|
else {
|
|
|
|
LPSTR ValueNameA = HEAP_strdupWtoA(GetProcessHeap(),0,ValueName);
|
|
|
|
ret = RegQueryValueExA(hkey, ValueNameA, 0, &type, ptr, &sz);
|
|
|
|
HeapFree(GetProcessHeap(),0,ValueNameA);
|
|
|
|
}
|
|
|
|
if(ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA) {
|
|
|
|
WARN("Got ret = %ld\n", ret);
|
|
|
|
*needed = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
*needed = sz;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WINSPOOL_GetDevModeFromReg
|
|
|
|
*
|
|
|
|
* Get ValueName from hkey storing result in ptr. buflen is space left in ptr
|
|
|
|
* DevMode is stored either as unicode or ascii.
|
|
|
|
*/
|
|
|
|
static BOOL WINSPOOL_GetDevModeFromReg(HKEY hkey, LPCWSTR ValueName,
|
|
|
|
LPBYTE ptr,
|
|
|
|
DWORD buflen, DWORD *needed,
|
|
|
|
BOOL unicode)
|
|
|
|
{
|
|
|
|
DWORD sz = buflen, type;
|
|
|
|
LONG ret;
|
1999-07-10 13:58:50 +02:00
|
|
|
|
2000-08-16 14:43:00 +02:00
|
|
|
if (ptr) memset(ptr, 0, sizeof(DEVMODEA));
|
2000-05-26 01:02:46 +02:00
|
|
|
ret = RegQueryValueExW(hkey, ValueName, 0, &type, ptr, &sz);
|
2000-08-16 14:43:00 +02:00
|
|
|
if ((ret != ERROR_SUCCESS && ret != ERROR_MORE_DATA)) sz = 0;
|
|
|
|
if (sz < sizeof(DEVMODEA))
|
|
|
|
{
|
|
|
|
ERR("corrupted registry for %s\n", debugstr_w(ValueName));
|
|
|
|
sz = sizeof(DEVMODEA);
|
1999-07-10 13:58:50 +02:00
|
|
|
}
|
2000-08-16 14:43:00 +02:00
|
|
|
/* ensures that dmSize is not erratically bogus if registry is invalid */
|
|
|
|
if (ptr && ((DEVMODEA*)ptr)->dmSize < sizeof(DEVMODEA))
|
|
|
|
((DEVMODEA*)ptr)->dmSize = sizeof(DEVMODEA);
|
2000-05-26 01:02:46 +02:00
|
|
|
if(unicode) {
|
|
|
|
sz += (CCHDEVICENAME + CCHFORMNAME);
|
|
|
|
if(buflen >= sz) {
|
|
|
|
DEVMODEW *dmW = DEVMODEdupAtoW(GetProcessHeap(), (DEVMODEA*)ptr);
|
|
|
|
memcpy(ptr, dmW, sz);
|
|
|
|
HeapFree(GetProcessHeap(),0,dmW);
|
|
|
|
}
|
|
|
|
}
|
1999-07-10 13:58:50 +02:00
|
|
|
*needed = sz;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-09-10 16:37:29 +02:00
|
|
|
/*********************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetPrinter_2
|
1999-09-10 16:37:29 +02:00
|
|
|
*
|
2000-05-26 01:02:46 +02:00
|
|
|
* Fills out a PRINTER_INFO_2A|W struct storing the strings in buf.
|
|
|
|
* The strings are either stored as unicode or ascii.
|
1999-09-10 16:37:29 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_GetPrinter_2(HKEY hkeyPrinter, PRINTER_INFO_2W *pi2,
|
|
|
|
LPBYTE buf, DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
BOOL unicode)
|
1999-09-10 16:37:29 +02:00
|
|
|
{
|
|
|
|
DWORD size, left = cbBuf;
|
|
|
|
BOOL space = (cbBuf > 0);
|
|
|
|
LPBYTE ptr = buf;
|
|
|
|
|
|
|
|
*pcbNeeded = 0;
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, NameW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pPrinterName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, Share_NameW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pShareName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, PortW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pPortName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, Printer_DriverW, ptr, left,
|
|
|
|
&size, unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pDriverName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, DescriptionW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pComment = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, LocationW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pLocation = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetDevModeFromReg(hkeyPrinter, Default_DevModeW, ptr, left,
|
|
|
|
&size, unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pDevMode = (LPDEVMODEW)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, Separator_FileW, ptr, left,
|
|
|
|
&size, unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pSepFile = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, Print_ProcessorW, ptr, left,
|
|
|
|
&size, unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pPrintProcessor = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, DatatypeW, ptr, left,
|
|
|
|
&size, unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pDatatype = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, ParametersW, ptr, left,
|
|
|
|
&size, unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi2->pParameters = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(pi2) {
|
|
|
|
pi2->Attributes = WINSPOOL_GetDWORDFromReg(hkeyPrinter, "Attributes");
|
|
|
|
pi2->Priority = WINSPOOL_GetDWORDFromReg(hkeyPrinter, "Priority");
|
|
|
|
pi2->DefaultPriority = WINSPOOL_GetDWORDFromReg(hkeyPrinter,
|
|
|
|
"Default Priority");
|
|
|
|
pi2->StartTime = WINSPOOL_GetDWORDFromReg(hkeyPrinter, "StartTime");
|
|
|
|
pi2->UntilTime = WINSPOOL_GetDWORDFromReg(hkeyPrinter, "UntilTime");
|
|
|
|
}
|
1999-09-10 16:37:29 +02:00
|
|
|
|
|
|
|
if(!space && pi2) /* zero out pi2 if we can't completely fill buf */
|
|
|
|
memset(pi2, 0, sizeof(*pi2));
|
|
|
|
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetPrinter_4
|
1999-09-10 16:37:29 +02:00
|
|
|
*
|
2000-05-26 01:02:46 +02:00
|
|
|
* Fills out a PRINTER_INFO_4 struct storing the strings in buf.
|
1999-09-10 16:37:29 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_GetPrinter_4(HKEY hkeyPrinter, PRINTER_INFO_4W *pi4,
|
|
|
|
LPBYTE buf, DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
BOOL unicode)
|
1999-09-10 16:37:29 +02:00
|
|
|
{
|
|
|
|
DWORD size, left = cbBuf;
|
|
|
|
BOOL space = (cbBuf > 0);
|
|
|
|
LPBYTE ptr = buf;
|
|
|
|
|
|
|
|
*pcbNeeded = 0;
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, NameW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi4->pPrinterName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(pi4) {
|
|
|
|
pi4->Attributes = WINSPOOL_GetDWORDFromReg(hkeyPrinter, "Attributes");
|
|
|
|
}
|
1999-09-10 16:37:29 +02:00
|
|
|
|
|
|
|
if(!space && pi4) /* zero out pi4 if we can't completely fill buf */
|
|
|
|
memset(pi4, 0, sizeof(*pi4));
|
|
|
|
|
|
|
|
return space;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetPrinter_5
|
1999-09-10 16:37:29 +02:00
|
|
|
*
|
2000-05-26 01:02:46 +02:00
|
|
|
* Fills out a PRINTER_INFO_5 struct storing the strings in buf.
|
1999-09-10 16:37:29 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_GetPrinter_5(HKEY hkeyPrinter, PRINTER_INFO_5W *pi5,
|
|
|
|
LPBYTE buf, DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
BOOL unicode)
|
1999-09-10 16:37:29 +02:00
|
|
|
{
|
|
|
|
DWORD size, left = cbBuf;
|
|
|
|
BOOL space = (cbBuf > 0);
|
|
|
|
LPBYTE ptr = buf;
|
|
|
|
|
|
|
|
*pcbNeeded = 0;
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, NameW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi5->pPrinterName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyPrinter, PortW, ptr, left, &size,
|
|
|
|
unicode)) {
|
|
|
|
if(space && size <= left) {
|
|
|
|
pi5->pPortName = (LPWSTR)ptr;
|
|
|
|
ptr += size;
|
|
|
|
left -= size;
|
|
|
|
} else
|
|
|
|
space = FALSE;
|
|
|
|
*pcbNeeded += size;
|
|
|
|
}
|
|
|
|
if(pi5) {
|
|
|
|
pi5->Attributes = WINSPOOL_GetDWORDFromReg(hkeyPrinter, "Attributes");
|
|
|
|
pi5->DeviceNotSelectedTimeout = WINSPOOL_GetDWORDFromReg(hkeyPrinter,
|
|
|
|
"dnsTimeout");
|
|
|
|
pi5->TransmissionRetryTimeout = WINSPOOL_GetDWORDFromReg(hkeyPrinter,
|
|
|
|
"txTimeout");
|
|
|
|
}
|
1999-09-10 16:37:29 +02:00
|
|
|
|
|
|
|
if(!space && pi5) /* zero out pi5 if we can't completely fill buf */
|
|
|
|
memset(pi5, 0, sizeof(*pi5));
|
|
|
|
|
|
|
|
return space;
|
|
|
|
}
|
1999-07-10 13:58:50 +02:00
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
/*****************************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetPrinter
|
|
|
|
*
|
|
|
|
* Implementation of GetPrinterA|W. Relies on PRINTER_INFO_*W being
|
|
|
|
* essentially the same as PRINTER_INFO_*A. i.e. the structure itself is
|
|
|
|
* just a collection of pointers to strings.
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_GetPrinter(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded, BOOL unicode)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
OPENEDPRINTER *lpOpenedPrinter;
|
1999-07-10 13:58:50 +02:00
|
|
|
DWORD size, needed = 0;
|
|
|
|
LPBYTE ptr = NULL;
|
|
|
|
HKEY hkeyPrinter, hkeyPrinters;
|
1999-09-10 16:37:29 +02:00
|
|
|
BOOL ret;
|
|
|
|
|
1999-07-10 13:58:50 +02:00
|
|
|
TRACE("(%d,%ld,%p,%ld,%p)\n",hPrinter,Level,pPrinter,cbBuf, pcbNeeded);
|
1999-05-17 18:20:51 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
lpOpenedPrinter = WINSPOOL_GetOpenedPrinter(hPrinter);
|
1999-07-10 13:58:50 +02:00
|
|
|
if(!lpOpenedPrinter) {
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't create Printers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
if(RegOpenKeyW(hkeyPrinters, lpOpenedPrinter->lpsPrinterName, &hkeyPrinter)
|
1999-07-10 13:58:50 +02:00
|
|
|
!= ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
ERR("Can't find opened printer %s in registry\n",
|
|
|
|
debugstr_w(lpOpenedPrinter->lpsPrinterName));
|
1999-07-10 13:58:50 +02:00
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
SetLastError(ERROR_INVALID_PRINTER_NAME); /* ? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-07-10 13:58:50 +02:00
|
|
|
switch(Level) {
|
|
|
|
case 2:
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
PRINTER_INFO_2W *pi2 = (PRINTER_INFO_2W *)pPrinter;
|
1999-07-10 13:58:50 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
size = sizeof(PRINTER_INFO_2W);
|
1999-07-10 13:58:50 +02:00
|
|
|
if(size <= cbBuf) {
|
|
|
|
ptr = pPrinter + size;
|
|
|
|
cbBuf -= size;
|
|
|
|
memset(pPrinter, 0, size);
|
1999-09-10 16:37:29 +02:00
|
|
|
} else {
|
|
|
|
pi2 = NULL;
|
1999-07-10 13:58:50 +02:00
|
|
|
cbBuf = 0;
|
1999-09-10 16:37:29 +02:00
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
ret = WINSPOOL_GetPrinter_2(hkeyPrinter, pi2, ptr, cbBuf, &needed,
|
|
|
|
unicode);
|
1999-07-10 13:58:50 +02:00
|
|
|
needed += size;
|
1999-09-10 16:37:29 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
PRINTER_INFO_4W *pi4 = (PRINTER_INFO_4W *)pPrinter;
|
1999-09-10 16:37:29 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
size = sizeof(PRINTER_INFO_4W);
|
1999-09-10 16:37:29 +02:00
|
|
|
if(size <= cbBuf) {
|
|
|
|
ptr = pPrinter + size;
|
|
|
|
cbBuf -= size;
|
|
|
|
memset(pPrinter, 0, size);
|
|
|
|
} else {
|
|
|
|
pi4 = NULL;
|
1999-07-10 13:58:50 +02:00
|
|
|
cbBuf = 0;
|
1999-09-10 16:37:29 +02:00
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
ret = WINSPOOL_GetPrinter_4(hkeyPrinter, pi4, ptr, cbBuf, &needed,
|
|
|
|
unicode);
|
1999-07-10 13:58:50 +02:00
|
|
|
needed += size;
|
|
|
|
break;
|
|
|
|
}
|
1999-09-10 16:37:29 +02:00
|
|
|
|
|
|
|
|
1999-07-10 13:58:50 +02:00
|
|
|
case 5:
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
PRINTER_INFO_5W *pi5 = (PRINTER_INFO_5W *)pPrinter;
|
1999-07-10 13:58:50 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
size = sizeof(PRINTER_INFO_5W);
|
1999-07-10 13:58:50 +02:00
|
|
|
if(size <= cbBuf) {
|
|
|
|
ptr = pPrinter + size;
|
|
|
|
cbBuf -= size;
|
|
|
|
memset(pPrinter, 0, size);
|
1999-09-10 16:37:29 +02:00
|
|
|
} else {
|
|
|
|
pi5 = NULL;
|
1999-07-10 13:58:50 +02:00
|
|
|
cbBuf = 0;
|
1999-09-10 16:37:29 +02:00
|
|
|
}
|
1999-07-10 13:58:50 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
ret = WINSPOOL_GetPrinter_5(hkeyPrinter, pi5, ptr, cbBuf, &needed,
|
|
|
|
unicode);
|
1999-07-10 13:58:50 +02:00
|
|
|
needed += size;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unimplemented level %ld\n", Level);
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
RegCloseKey(hkeyPrinter);
|
1999-05-17 18:20:51 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-07-10 13:58:50 +02:00
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
TRACE("returing %d needed = %ld\n", ret, needed);
|
1999-07-10 13:58:50 +02:00
|
|
|
if(pcbNeeded) *pcbNeeded = needed;
|
1999-09-10 16:37:29 +02:00
|
|
|
if(!ret)
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return ret;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
1999-09-10 16:37:29 +02:00
|
|
|
* GetPrinterW [WINSPOOL.194]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetPrinterW(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
|
2000-05-26 01:02:46 +02:00
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
return WINSPOOL_GetPrinter(hPrinter, Level, pPrinter, cbBuf, pcbNeeded,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GetPrinterA [WINSPOOL.187]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetPrinterA(HANDLE hPrinter, DWORD Level, LPBYTE pPrinter,
|
1999-05-17 18:20:51 +02:00
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
return WINSPOOL_GetPrinter(hPrinter, Level, pPrinter, cbBuf, pcbNeeded,
|
|
|
|
FALSE);
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* WINSPOOL_EnumPrinters
|
1999-10-31 18:34:31 +01:00
|
|
|
*
|
2000-05-26 01:02:46 +02:00
|
|
|
* Implementation of EnumPrintersA|W
|
1999-10-31 18:34:31 +01:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_EnumPrinters(DWORD dwType, LPWSTR lpszName,
|
|
|
|
DWORD dwLevel, LPBYTE lpbPrinters,
|
|
|
|
DWORD cbBuf, LPDWORD lpdwNeeded,
|
|
|
|
LPDWORD lpdwReturned, BOOL unicode)
|
1999-10-31 18:34:31 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
HKEY hkeyPrinters, hkeyPrinter;
|
2000-05-26 01:02:46 +02:00
|
|
|
WCHAR PrinterName[255];
|
1999-10-31 18:34:31 +01:00
|
|
|
DWORD needed = 0, number = 0;
|
|
|
|
DWORD used, i, left;
|
|
|
|
PBYTE pi, buf;
|
|
|
|
|
|
|
|
if(lpbPrinters)
|
|
|
|
memset(lpbPrinters, 0, cbBuf);
|
|
|
|
if(lpdwReturned)
|
|
|
|
*lpdwReturned = 0;
|
2001-01-09 21:52:17 +01:00
|
|
|
if(lpdwNeeded)
|
|
|
|
*lpdwNeeded = 0;
|
|
|
|
|
|
|
|
/* PRINTER_ENUM_DEFAULT is only supported under win9x, we behave like NT */
|
|
|
|
if(dwType == PRINTER_ENUM_DEFAULT)
|
|
|
|
return TRUE;
|
1999-10-31 18:34:31 +01:00
|
|
|
|
|
|
|
if (!((dwType & PRINTER_ENUM_LOCAL) || (dwType & PRINTER_ENUM_NAME))) {
|
|
|
|
FIXME("dwType = %08lx\n", dwType);
|
|
|
|
SetLastError(ERROR_INVALID_FLAGS);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't create Printers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-11-28 20:47:58 +01:00
|
|
|
if(RegQueryInfoKeyA(hkeyPrinters, NULL, NULL, NULL, &number, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) {
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
ERR("Can't query Printers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-10-31 18:34:31 +01:00
|
|
|
TRACE("Found %ld printers\n", number);
|
|
|
|
|
|
|
|
switch(dwLevel) {
|
|
|
|
case 1:
|
|
|
|
RegCloseKey(hkeyPrinters);
|
2000-02-25 22:38:17 +01:00
|
|
|
if (lpdwReturned)
|
|
|
|
*lpdwReturned = number;
|
1999-10-31 18:34:31 +01:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case 2:
|
2000-05-26 01:02:46 +02:00
|
|
|
used = number * sizeof(PRINTER_INFO_2W);
|
1999-10-31 18:34:31 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2000-05-26 01:02:46 +02:00
|
|
|
used = number * sizeof(PRINTER_INFO_4W);
|
1999-10-31 18:34:31 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2000-05-26 01:02:46 +02:00
|
|
|
used = number * sizeof(PRINTER_INFO_5W);
|
1999-10-31 18:34:31 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pi = (used <= cbBuf) ? lpbPrinters : NULL;
|
|
|
|
|
|
|
|
for(i = 0; i < number; i++) {
|
2000-05-26 01:02:46 +02:00
|
|
|
if(RegEnumKeyW(hkeyPrinters, i, PrinterName, sizeof(PrinterName)) !=
|
1999-10-31 18:34:31 +01:00
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't enum key number %ld\n", i);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
TRACE("Printer %ld is %s\n", i, debugstr_w(PrinterName));
|
|
|
|
if(RegOpenKeyW(hkeyPrinters, PrinterName, &hkeyPrinter) !=
|
1999-10-31 18:34:31 +01:00
|
|
|
ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
ERR("Can't open key %s\n", debugstr_w(PrinterName));
|
1999-10-31 18:34:31 +01:00
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(cbBuf > used) {
|
|
|
|
buf = lpbPrinters + used;
|
|
|
|
left = cbBuf - used;
|
|
|
|
} else {
|
|
|
|
buf = NULL;
|
|
|
|
left = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(dwLevel) {
|
|
|
|
case 2:
|
2000-05-26 01:02:46 +02:00
|
|
|
WINSPOOL_GetPrinter_2(hkeyPrinter, (PRINTER_INFO_2W *)pi, buf,
|
|
|
|
left, &needed, unicode);
|
1999-10-31 18:34:31 +01:00
|
|
|
used += needed;
|
2000-05-26 01:02:46 +02:00
|
|
|
if(pi) pi += sizeof(PRINTER_INFO_2W);
|
1999-10-31 18:34:31 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2000-05-26 01:02:46 +02:00
|
|
|
WINSPOOL_GetPrinter_4(hkeyPrinter, (PRINTER_INFO_4W *)pi, buf,
|
|
|
|
left, &needed, unicode);
|
1999-10-31 18:34:31 +01:00
|
|
|
used += needed;
|
2000-05-26 01:02:46 +02:00
|
|
|
if(pi) pi += sizeof(PRINTER_INFO_4W);
|
1999-10-31 18:34:31 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2000-05-26 01:02:46 +02:00
|
|
|
WINSPOOL_GetPrinter_5(hkeyPrinter, (PRINTER_INFO_5W *)pi, buf,
|
|
|
|
left, &needed, unicode);
|
1999-10-31 18:34:31 +01:00
|
|
|
used += needed;
|
2000-05-26 01:02:46 +02:00
|
|
|
if(pi) pi += sizeof(PRINTER_INFO_5W);
|
1999-10-31 18:34:31 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Shouldn't be here!\n");
|
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
}
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
|
|
|
|
if(lpdwNeeded)
|
|
|
|
*lpdwNeeded = used;
|
2000-05-26 01:02:46 +02:00
|
|
|
|
1999-10-31 18:34:31 +01:00
|
|
|
if(used > cbBuf) {
|
|
|
|
if(lpbPrinters)
|
|
|
|
memset(lpbPrinters, 0, cbBuf);
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(lpdwReturned)
|
|
|
|
*lpdwReturned = number;
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
|
1999-10-31 18:34:31 +01:00
|
|
|
/******************************************************************
|
|
|
|
* EnumPrintersW [WINSPOOL.175]
|
|
|
|
*
|
2000-05-26 01:02:46 +02:00
|
|
|
* Enumerates the available printers, print servers and print
|
|
|
|
* providers, depending on the specified flags, name and level.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
*
|
|
|
|
* If level is set to 1:
|
|
|
|
* Not implemented yet!
|
|
|
|
* Returns TRUE with an empty list.
|
|
|
|
*
|
|
|
|
* If level is set to 2:
|
|
|
|
* Possible flags: PRINTER_ENUM_CONNECTIONS, PRINTER_ENUM_LOCAL.
|
|
|
|
* Returns an array of PRINTER_INFO_2 data structures in the
|
|
|
|
* lpbPrinters buffer. Note that according to MSDN also an
|
|
|
|
* OpenPrinter should be performed on every remote printer.
|
|
|
|
*
|
|
|
|
* If level is set to 4 (officially WinNT only):
|
|
|
|
* Possible flags: PRINTER_ENUM_CONNECTIONS, PRINTER_ENUM_LOCAL.
|
|
|
|
* Fast: Only the registry is queried to retrieve printer names,
|
|
|
|
* no connection to the driver is made.
|
|
|
|
* Returns an array of PRINTER_INFO_4 data structures in the
|
|
|
|
* lpbPrinters buffer.
|
|
|
|
*
|
|
|
|
* If level is set to 5 (officially WinNT4/Win9x only):
|
|
|
|
* Fast: Only the registry is queried to retrieve printer names,
|
|
|
|
* no connection to the driver is made.
|
|
|
|
* Returns an array of PRINTER_INFO_5 data structures in the
|
|
|
|
* lpbPrinters buffer.
|
|
|
|
*
|
|
|
|
* If level set to 3 or 6+:
|
|
|
|
* returns zero (faillure!)
|
|
|
|
*
|
|
|
|
* Returns nonzero (TRUE) on succes, or zero on faillure, use GetLastError
|
|
|
|
* for information.
|
|
|
|
*
|
|
|
|
* BUGS:
|
|
|
|
* - Only PRINTER_ENUM_LOCAL and PRINTER_ENUM_NAME are implemented.
|
|
|
|
* - Only levels 2, 4 and 5 are implemented at the moment.
|
|
|
|
* - 16-bit printer drivers are not enumerated.
|
|
|
|
* - Returned amount of bytes used/needed does not match the real Windoze
|
|
|
|
* implementation (as in this implementation, all strings are part
|
|
|
|
* of the buffer, whereas Win32 keeps them somewhere else)
|
|
|
|
* - At level 2, EnumPrinters should also call OpenPrinter for remote printers.
|
|
|
|
*
|
|
|
|
* NOTE:
|
|
|
|
* - In a regular Wine installation, no registry settings for printers
|
|
|
|
* exist, which makes this function return an empty list.
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumPrintersW(
|
2000-12-02 00:58:28 +01:00
|
|
|
DWORD dwType, /* [in] Types of print objects to enumerate */
|
|
|
|
LPWSTR lpszName, /* [in] name of objects to enumerate */
|
|
|
|
DWORD dwLevel, /* [in] type of printer info structure */
|
|
|
|
LPBYTE lpbPrinters, /* [out] buffer which receives info */
|
|
|
|
DWORD cbBuf, /* [in] max size of buffer in bytes */
|
|
|
|
LPDWORD lpdwNeeded, /* [out] pointer to var: # bytes used/needed */
|
|
|
|
LPDWORD lpdwReturned /* [out] number of entries returned */
|
2000-05-26 01:02:46 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return WINSPOOL_EnumPrinters(dwType, lpszName, dwLevel, lpbPrinters, cbBuf,
|
|
|
|
lpdwNeeded, lpdwReturned, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EnumPrintersA [WINSPOOL.174]
|
|
|
|
*
|
1999-10-31 18:34:31 +01:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
BOOL WINAPI EnumPrintersA(DWORD dwType, LPSTR lpszName,
|
|
|
|
DWORD dwLevel, LPBYTE lpbPrinters,
|
|
|
|
DWORD cbBuf, LPDWORD lpdwNeeded,
|
|
|
|
LPDWORD lpdwReturned)
|
1999-10-31 18:34:31 +01:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
BOOL ret;
|
|
|
|
LPWSTR lpszNameW = HEAP_strdupAtoW(GetProcessHeap(),0,lpszName);
|
|
|
|
|
|
|
|
ret = WINSPOOL_EnumPrinters(dwType, lpszNameW, dwLevel, lpbPrinters, cbBuf,
|
|
|
|
lpdwNeeded, lpdwReturned, FALSE);
|
|
|
|
HeapFree(GetProcessHeap(),0,lpszNameW);
|
|
|
|
return ret;
|
1999-10-31 18:34:31 +01:00
|
|
|
}
|
|
|
|
|
2000-09-29 23:05:11 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* WINSPOOL_GetDriverInfoFromReg [internal]
|
|
|
|
*
|
|
|
|
* Enters the information from the registry into the DRIVER_INFO struct
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* zero if the printer driver does not exist in the registry
|
|
|
|
* (only if Level > 1) otherwise nonzero
|
|
|
|
*/
|
|
|
|
static BOOL WINSPOOL_GetDriverInfoFromReg(
|
|
|
|
HKEY hkeyDrivers,
|
|
|
|
LPWSTR DriverName,
|
|
|
|
LPWSTR pEnvironment,
|
|
|
|
DWORD Level,
|
|
|
|
LPBYTE ptr, /* DRIVER_INFO */
|
|
|
|
LPBYTE pDriverStrings, /* strings buffer */
|
|
|
|
DWORD cbBuf, /* size of string buffer */
|
|
|
|
LPDWORD pcbNeeded, /* space needed for str. */
|
|
|
|
BOOL unicode) /* type of strings */
|
2000-11-12 04:39:53 +01:00
|
|
|
{ DWORD dw, size, tmp, type;
|
2000-09-29 23:05:11 +02:00
|
|
|
HKEY hkeyDriver;
|
|
|
|
LPBYTE strPtr = pDriverStrings;
|
|
|
|
|
|
|
|
TRACE("%s,%s,%ld,%p,%p,%ld,%d\n",
|
|
|
|
debugstr_w(DriverName), debugstr_w(pEnvironment),
|
|
|
|
Level, ptr, pDriverStrings, cbBuf, unicode);
|
|
|
|
|
|
|
|
if(unicode) {
|
|
|
|
*pcbNeeded = (lstrlenW(DriverName) + 1) * sizeof(WCHAR);
|
|
|
|
if (*pcbNeeded <= cbBuf)
|
|
|
|
strcpyW((LPWSTR)strPtr, DriverName);
|
|
|
|
} else {
|
|
|
|
*pcbNeeded = WideCharToMultiByte(CP_ACP, 0, DriverName, -1, NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, DriverName, -1, strPtr, *pcbNeeded,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
if(Level == 1) {
|
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_1W) ptr)->pName = (LPWSTR) strPtr;
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pName = (LPWSTR) strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RegOpenKeyW(hkeyDrivers, DriverName, &hkeyDriver) != ERROR_SUCCESS) {
|
|
|
|
ERR("Can't find driver %s in registry\n", debugstr_w(DriverName));
|
|
|
|
SetLastError(ERROR_UNKNOWN_PRINTER_DRIVER); /* ? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = sizeof(dw);
|
|
|
|
if(RegQueryValueExA(hkeyDriver, "Version", 0, &type, (PBYTE)&dw, &size) !=
|
|
|
|
ERROR_SUCCESS)
|
|
|
|
WARN("Can't get Version\n");
|
|
|
|
else if(ptr)
|
|
|
|
((PDRIVER_INFO_3A) ptr)->cVersion = dw;
|
|
|
|
|
|
|
|
if(!pEnvironment)
|
|
|
|
pEnvironment = DefaultEnvironmentW;
|
|
|
|
if(unicode)
|
|
|
|
size = (lstrlenW(pEnvironment) + 1) * sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
size = WideCharToMultiByte(CP_ACP, 0, pEnvironment, -1, NULL, 0,
|
|
|
|
NULL, NULL);
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf) {
|
|
|
|
if(unicode)
|
|
|
|
strcpyW((LPWSTR)strPtr, pEnvironment);
|
|
|
|
else
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, pEnvironment, -1, strPtr, size,
|
|
|
|
NULL, NULL);
|
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pEnvironment = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, DriverW, strPtr, 0, &size,
|
|
|
|
unicode)) {
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
2000-11-12 04:39:53 +01:00
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, DriverW, strPtr, size, &tmp,
|
2000-09-29 23:05:11 +02:00
|
|
|
unicode);
|
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pDriverPath = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? (pDriverStrings + (*pcbNeeded)) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, Data_FileW, strPtr, 0, &size,
|
|
|
|
unicode)) {
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
2000-11-12 04:39:53 +01:00
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, Data_FileW, strPtr, size,
|
|
|
|
&tmp, unicode);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pDataFile = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, Configuration_FileW, strPtr,
|
2000-11-12 04:39:53 +01:00
|
|
|
0, &size, unicode)) {
|
2000-09-29 23:05:11 +02:00
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, Configuration_FileW, strPtr,
|
2000-11-12 04:39:53 +01:00
|
|
|
size, &tmp, unicode);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pConfigFile = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Level == 2 ) {
|
|
|
|
RegCloseKey(hkeyDriver);
|
2000-11-12 04:39:53 +01:00
|
|
|
TRACE("buffer space %ld required %ld\n", cbBuf, *pcbNeeded);
|
2000-09-29 23:05:11 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, Help_FileW, strPtr, 0, &size,
|
|
|
|
unicode)) {
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, Help_FileW, strPtr,
|
2000-11-12 04:39:53 +01:00
|
|
|
size, &tmp, unicode);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pHelpFile = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, Dependent_FilesW, strPtr, 0,
|
|
|
|
&size, unicode)) {
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, Dependent_FilesW, strPtr,
|
2000-11-12 04:39:53 +01:00
|
|
|
size, &tmp, unicode);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pDependentFiles = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr, 0, &size,
|
|
|
|
unicode)) {
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr,
|
2000-11-12 04:39:53 +01:00
|
|
|
size, &tmp, unicode);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pMonitorName = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(WINSPOOL_GetStringFromReg(hkeyDriver, DatatypeW, strPtr, 0, &size,
|
|
|
|
unicode)) {
|
|
|
|
*pcbNeeded += size;
|
|
|
|
if(*pcbNeeded <= cbBuf)
|
|
|
|
WINSPOOL_GetStringFromReg(hkeyDriver, MonitorW, strPtr,
|
2000-11-12 04:39:53 +01:00
|
|
|
size, &tmp, unicode);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(ptr)
|
|
|
|
((PDRIVER_INFO_3W) ptr)->pDefaultDataType = (LPWSTR)strPtr;
|
|
|
|
strPtr = (pDriverStrings) ? pDriverStrings + (*pcbNeeded) : NULL;
|
|
|
|
}
|
|
|
|
|
2000-11-12 04:39:53 +01:00
|
|
|
TRACE("buffer space %ld required %ld\n", cbBuf, *pcbNeeded);
|
2000-09-29 23:05:11 +02:00
|
|
|
RegCloseKey(hkeyDriver);
|
|
|
|
return TRUE;
|
|
|
|
}
|
1999-07-10 13:58:50 +02:00
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
/*****************************************************************************
|
2000-05-26 01:02:46 +02:00
|
|
|
* WINSPOOL_GetPrinterDriver
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
2000-05-26 01:02:46 +02:00
|
|
|
static BOOL WINSPOOL_GetPrinterDriver(HANDLE hPrinter, LPWSTR pEnvironment,
|
|
|
|
DWORD Level, LPBYTE pDriverInfo,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
BOOL unicode)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
OPENEDPRINTER *lpOpenedPrinter;
|
|
|
|
WCHAR DriverName[100];
|
2000-09-29 23:05:11 +02:00
|
|
|
DWORD ret, type, size, needed = 0;
|
1999-07-10 13:58:50 +02:00
|
|
|
LPBYTE ptr = NULL;
|
2000-09-29 23:05:11 +02:00
|
|
|
HKEY hkeyPrinter, hkeyPrinters, hkeyDrivers;
|
1999-07-10 13:58:50 +02:00
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
TRACE("(%d,%s,%ld,%p,%ld,%p)\n",hPrinter,debugstr_w(pEnvironment),
|
|
|
|
Level,pDriverInfo,cbBuf, pcbNeeded);
|
1999-05-22 20:53:56 +02:00
|
|
|
|
2000-02-25 22:38:17 +01:00
|
|
|
ZeroMemory(pDriverInfo, cbBuf);
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
lpOpenedPrinter = WINSPOOL_GetOpenedPrinter(hPrinter);
|
1999-05-22 20:53:56 +02:00
|
|
|
if(!lpOpenedPrinter) {
|
|
|
|
SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-07-10 13:58:50 +02:00
|
|
|
if(Level < 1 || Level > 3) {
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(RegCreateKeyA(HKEY_LOCAL_MACHINE, Printers, &hkeyPrinters) !=
|
|
|
|
ERROR_SUCCESS) {
|
|
|
|
ERR("Can't create Printers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-05-26 01:02:46 +02:00
|
|
|
if(RegOpenKeyW(hkeyPrinters, lpOpenedPrinter->lpsPrinterName, &hkeyPrinter)
|
1999-07-10 13:58:50 +02:00
|
|
|
!= ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
ERR("Can't find opened printer %s in registry\n",
|
|
|
|
debugstr_w(lpOpenedPrinter->lpsPrinterName));
|
1999-07-10 13:58:50 +02:00
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
SetLastError(ERROR_INVALID_PRINTER_NAME); /* ? */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
size = sizeof(DriverName);
|
2000-05-26 01:02:46 +02:00
|
|
|
ret = RegQueryValueExW(hkeyPrinter, Printer_DriverW, 0, &type,
|
|
|
|
(LPBYTE)DriverName, &size);
|
1999-07-10 13:58:50 +02:00
|
|
|
RegCloseKey(hkeyPrinter);
|
|
|
|
RegCloseKey(hkeyPrinters);
|
|
|
|
if(ret != ERROR_SUCCESS) {
|
2000-05-26 01:02:46 +02:00
|
|
|
ERR("Can't get DriverName for printer %s\n",
|
|
|
|
debugstr_w(lpOpenedPrinter->lpsPrinterName));
|
1999-07-10 13:58:50 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2000-11-06 06:26:00 +01:00
|
|
|
|
|
|
|
hkeyDrivers = WINSPOOL_OpenDriverReg( pEnvironment, TRUE);
|
|
|
|
if(!hkeyDrivers) {
|
1999-07-10 13:58:50 +02:00
|
|
|
ERR("Can't create Drivers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(Level) {
|
|
|
|
case 1:
|
2000-05-26 01:02:46 +02:00
|
|
|
size = sizeof(DRIVER_INFO_1W);
|
1999-07-10 13:58:50 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2000-05-26 01:02:46 +02:00
|
|
|
size = sizeof(DRIVER_INFO_2W);
|
1999-07-10 13:58:50 +02:00
|
|
|
break;
|
|
|
|
case 3:
|
2000-05-26 01:02:46 +02:00
|
|
|
size = sizeof(DRIVER_INFO_3W);
|
1999-07-10 13:58:50 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Invalid level\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-09-29 23:05:11 +02:00
|
|
|
if(size <= cbBuf)
|
1999-07-10 13:58:50 +02:00
|
|
|
ptr = pDriverInfo + size;
|
|
|
|
|
2000-09-29 23:05:11 +02:00
|
|
|
if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverName,
|
|
|
|
pEnvironment, Level, pDriverInfo,
|
|
|
|
(cbBuf < size) ? NULL : ptr,
|
|
|
|
(cbBuf < size) ? 0 : cbBuf - size,
|
|
|
|
&needed, unicode)) {
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
return FALSE;
|
1999-07-10 13:58:50 +02:00
|
|
|
}
|
2000-09-29 23:05:11 +02:00
|
|
|
|
1999-07-10 13:58:50 +02:00
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
|
2000-11-12 04:39:53 +01:00
|
|
|
if(pcbNeeded) *pcbNeeded = size + needed;
|
|
|
|
TRACE("buffer space %ld required %ld\n", cbBuf, *pcbNeeded);
|
2000-09-29 23:05:11 +02:00
|
|
|
if(cbBuf >= needed) return TRUE;
|
1999-07-10 13:58:50 +02:00
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
1999-05-17 18:20:51 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-05-26 01:02:46 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* GetPrinterDriverA [WINSPOOL.190]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetPrinterDriverA(HANDLE hPrinter, LPSTR pEnvironment,
|
|
|
|
DWORD Level, LPBYTE pDriverInfo,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
LPWSTR pEnvW = HEAP_strdupAtoW(GetProcessHeap(),0,pEnvironment);
|
|
|
|
ret = WINSPOOL_GetPrinterDriver(hPrinter, pEnvW, Level, pDriverInfo,
|
|
|
|
cbBuf, pcbNeeded, FALSE);
|
|
|
|
HeapFree(GetProcessHeap(),0,pEnvW);
|
|
|
|
return ret;
|
|
|
|
}
|
1999-05-17 18:20:51 +02:00
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* GetPrinterDriverW [WINSPOOL.193]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI GetPrinterDriverW(HANDLE hPrinter, LPWSTR pEnvironment,
|
|
|
|
DWORD Level, LPBYTE pDriverInfo,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
2000-05-26 01:02:46 +02:00
|
|
|
return WINSPOOL_GetPrinterDriver(hPrinter, pEnvironment, Level,
|
|
|
|
pDriverInfo, cbBuf, pcbNeeded, TRUE);
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
1999-05-22 20:53:56 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GetPrinterDriverDirectoryA [WINSPOOL.191]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetPrinterDriverDirectoryA(LPSTR pName, LPSTR pEnvironment,
|
|
|
|
DWORD Level, LPBYTE pDriverDirectory,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
DWORD needed;
|
|
|
|
|
|
|
|
TRACE("(%s, %s, %ld, %p, %ld, %p)\n", pName, pEnvironment, Level,
|
|
|
|
pDriverDirectory, cbBuf, pcbNeeded);
|
|
|
|
if(pName != NULL) {
|
|
|
|
FIXME("pName = `%s' - unsupported\n", pName);
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(pEnvironment != NULL) {
|
|
|
|
FIXME("pEnvironment = `%s' - unsupported\n", pEnvironment);
|
|
|
|
SetLastError(ERROR_INVALID_ENVIRONMENT);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(Level != 1) /* win95 ignores this so we just carry on */
|
|
|
|
WARN("Level = %ld - assuming 1\n", Level);
|
|
|
|
|
|
|
|
/* FIXME should read from registry */
|
|
|
|
needed = GetSystemDirectoryA(pDriverDirectory, cbBuf);
|
|
|
|
needed++;
|
|
|
|
if(pcbNeeded)
|
|
|
|
*pcbNeeded = needed;
|
|
|
|
if(needed > cbBuf) {
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* GetPrinterDriverDirectoryW [WINSPOOL.192]
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetPrinterDriverDirectoryW(LPWSTR pName, LPWSTR pEnvironment,
|
|
|
|
DWORD Level, LPBYTE pDriverDirectory,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
LPSTR pNameA = NULL, pEnvironmentA = NULL;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if(pName)
|
|
|
|
pNameA = HEAP_strdupWtoA( GetProcessHeap(), 0, pName );
|
|
|
|
if(pEnvironment)
|
|
|
|
pEnvironmentA = HEAP_strdupWtoA( GetProcessHeap(), 0, pEnvironment );
|
|
|
|
ret = GetPrinterDriverDirectoryA( pNameA, pEnvironmentA, Level,
|
|
|
|
pDriverDirectory, cbBuf, pcbNeeded );
|
|
|
|
if(pNameA)
|
|
|
|
HeapFree( GetProcessHeap(), 0, pNameA );
|
|
|
|
if(pEnvironmentA)
|
2000-09-29 23:05:11 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, pEnvironmentA );
|
1999-05-22 20:53:56 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddPrinterDriverA [WINSPOOL.120]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
1999-05-22 20:53:56 +02:00
|
|
|
BOOL WINAPI AddPrinterDriverA(LPSTR pName, DWORD level, LPBYTE pDriverInfo)
|
1999-05-17 18:20:51 +02:00
|
|
|
{
|
1999-05-22 20:53:56 +02:00
|
|
|
DRIVER_INFO_3A di3;
|
|
|
|
HKEY hkeyDrivers, hkeyName;
|
|
|
|
|
|
|
|
TRACE("(%s,%ld,%p)\n",pName,level,pDriverInfo);
|
|
|
|
|
|
|
|
if(level != 2 && level != 3) {
|
|
|
|
SetLastError(ERROR_INVALID_LEVEL);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(pName != NULL) {
|
|
|
|
FIXME("pName= `%s' - unsupported\n", pName);
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(!pDriverInfo) {
|
|
|
|
WARN("pDriverInfo == NULL");
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(level == 3)
|
|
|
|
di3 = *(DRIVER_INFO_3A *)pDriverInfo;
|
|
|
|
else {
|
|
|
|
memset(&di3, 0, sizeof(di3));
|
|
|
|
*(DRIVER_INFO_2A *)&di3 = *(DRIVER_INFO_2A *)pDriverInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!di3.pName || !di3.pDriverPath || !di3.pConfigFile ||
|
|
|
|
!di3.pDataFile) {
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(!di3.pDefaultDataType) di3.pDefaultDataType = "";
|
|
|
|
if(!di3.pDependentFiles) di3.pDependentFiles = "\0";
|
|
|
|
if(!di3.pHelpFile) di3.pHelpFile = "";
|
|
|
|
if(!di3.pMonitorName) di3.pMonitorName = "";
|
|
|
|
|
2000-11-06 06:26:00 +01:00
|
|
|
hkeyDrivers = WINSPOOL_OpenDriverReg(di3.pEnvironment, FALSE);
|
|
|
|
|
|
|
|
if(!hkeyDrivers) {
|
1999-05-22 20:53:56 +02:00
|
|
|
ERR("Can't create Drivers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(level == 2) { /* apparently can't overwrite with level2 */
|
|
|
|
if(RegOpenKeyA(hkeyDrivers, di3.pName, &hkeyName) == ERROR_SUCCESS) {
|
|
|
|
RegCloseKey(hkeyName);
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
WARN("Trying to create existing printer driver `%s'\n", di3.pName);
|
|
|
|
SetLastError(ERROR_PRINTER_DRIVER_ALREADY_INSTALLED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(RegCreateKeyA(hkeyDrivers, di3.pName, &hkeyName) != ERROR_SUCCESS) {
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
ERR("Can't create Name key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
RegSetValueExA(hkeyName, "Configuration File", 0, REG_SZ, di3.pConfigFile,
|
|
|
|
0);
|
|
|
|
RegSetValueExA(hkeyName, "Data File", 0, REG_SZ, di3.pDataFile, 0);
|
|
|
|
RegSetValueExA(hkeyName, "Driver", 0, REG_SZ, di3.pDriverPath, 0);
|
|
|
|
RegSetValueExA(hkeyName, "Version", 0, REG_DWORD, (LPSTR)&di3.cVersion,
|
|
|
|
sizeof(DWORD));
|
|
|
|
RegSetValueExA(hkeyName, "Datatype", 0, REG_SZ, di3.pDefaultDataType, 0);
|
|
|
|
RegSetValueExA(hkeyName, "Dependent Files", 0, REG_MULTI_SZ,
|
|
|
|
di3.pDependentFiles, 0);
|
|
|
|
RegSetValueExA(hkeyName, "Help File", 0, REG_SZ, di3.pHelpFile, 0);
|
|
|
|
RegSetValueExA(hkeyName, "Monitor", 0, REG_SZ, di3.pMonitorName, 0);
|
|
|
|
RegCloseKey(hkeyName);
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
|
|
|
|
return TRUE;
|
1999-05-17 18:20:51 +02:00
|
|
|
}
|
|
|
|
/*****************************************************************************
|
2000-03-28 22:22:59 +02:00
|
|
|
* AddPrinterDriverW [WINSPOOL.121]
|
1999-05-17 18:20:51 +02:00
|
|
|
*/
|
|
|
|
BOOL WINAPI AddPrinterDriverW(LPWSTR printerName,DWORD level,
|
|
|
|
LPBYTE pDriverInfo)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%ld,%p): stub\n",debugstr_w(printerName),
|
|
|
|
level,pDriverInfo);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* PrinterProperties [WINSPOOL.201]
|
|
|
|
*
|
|
|
|
* Displays a dialog to set the properties of the printer.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on succes or zero on faillure
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* implemented as stub only
|
|
|
|
*/
|
2000-12-02 00:58:28 +01:00
|
|
|
BOOL WINAPI PrinterProperties(HWND hWnd, /* [in] handle to parent window */
|
|
|
|
HANDLE hPrinter /* [in] handle to printer object */
|
1999-05-17 18:20:51 +02:00
|
|
|
){
|
|
|
|
FIXME("(%d,%d): stub\n", hWnd, hPrinter);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
1999-07-23 21:23:49 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* EnumJobsA [WINSPOOL.162]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumJobsA(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs,
|
|
|
|
DWORD Level, LPBYTE pJob, DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
LPDWORD pcReturned)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
if(pcbNeeded) *pcbNeeded = 0;
|
|
|
|
if(pcReturned) *pcReturned = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1999-05-17 18:20:51 +02:00
|
|
|
|
1999-07-23 21:23:49 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* EnumJobsW [WINSPOOL.163]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumJobsW(HANDLE hPrinter, DWORD FirstJob, DWORD NoJobs,
|
|
|
|
DWORD Level, LPBYTE pJob, DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
LPDWORD pcReturned)
|
|
|
|
{
|
|
|
|
FIXME("stub\n");
|
|
|
|
if(pcbNeeded) *pcbNeeded = 0;
|
|
|
|
if(pcReturned) *pcReturned = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-09-29 23:05:11 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* WINSPOOL_EnumPrinterDrivers [internal]
|
|
|
|
*
|
|
|
|
* Delivers information about all installed printer drivers installed on
|
|
|
|
* localhost or a given server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* nonzero on succes or zero on failure, if the buffer for the returned
|
|
|
|
* information is too small the function will return an error
|
|
|
|
*
|
|
|
|
* BUGS
|
|
|
|
* - only implemented for localhost, foreign hosts will return an error
|
|
|
|
*/
|
|
|
|
static BOOL WINSPOOL_EnumPrinterDrivers(LPWSTR pName, LPWSTR pEnvironment,
|
|
|
|
DWORD Level, LPBYTE pDriverInfo,
|
|
|
|
DWORD cbBuf, LPDWORD pcbNeeded,
|
|
|
|
LPDWORD pcReturned, BOOL unicode)
|
|
|
|
|
|
|
|
{ HKEY hkeyDrivers;
|
|
|
|
DWORD i, needed, number = 0, size = 0;
|
|
|
|
WCHAR DriverNameW[255];
|
|
|
|
PBYTE ptr;
|
|
|
|
|
|
|
|
TRACE("%s,%s,%ld,%p,%ld,%d\n",
|
|
|
|
debugstr_w(pName), debugstr_w(pEnvironment),
|
|
|
|
Level, pDriverInfo, cbBuf, unicode);
|
|
|
|
|
|
|
|
/* check for local drivers */
|
|
|
|
if(pName) {
|
|
|
|
ERR("remote drivers unsupported! Current remote host is %s\n",
|
|
|
|
debugstr_w(pName));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check input parameter */
|
|
|
|
if((Level < 1) || (Level > 3)) {
|
|
|
|
ERR("unsupported level %ld \n", Level);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize return values */
|
|
|
|
if(pDriverInfo)
|
|
|
|
memset( pDriverInfo, 0, cbBuf);
|
|
|
|
*pcbNeeded = 0;
|
|
|
|
*pcReturned = 0;
|
|
|
|
|
2000-11-06 06:26:00 +01:00
|
|
|
hkeyDrivers = WINSPOOL_OpenDriverReg(pEnvironment, TRUE);
|
|
|
|
if(!hkeyDrivers) {
|
2000-09-29 23:05:11 +02:00
|
|
|
ERR("Can't open Drivers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(RegQueryInfoKeyA(hkeyDrivers, NULL, NULL, NULL, &number, NULL, NULL,
|
|
|
|
NULL, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) {
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
ERR("Can't query Drivers key\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
TRACE("Found %ld Drivers\n", number);
|
|
|
|
|
|
|
|
/* get size of single struct
|
|
|
|
* unicode and ascii structure have the same size
|
|
|
|
*/
|
|
|
|
switch (Level) {
|
|
|
|
case 1:
|
|
|
|
size = sizeof(DRIVER_INFO_1A);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
size = sizeof(DRIVER_INFO_2A);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
size = sizeof(DRIVER_INFO_3A);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate required buffer size */
|
|
|
|
*pcbNeeded = size * number;
|
|
|
|
|
|
|
|
for( i = 0, ptr = (pDriverInfo && (cbBuf >= size)) ? pDriverInfo : NULL ;
|
|
|
|
i < number;
|
|
|
|
i++, ptr = (ptr && (cbBuf >= size * i)) ? ptr + size : NULL) {
|
|
|
|
if(RegEnumKeyW(hkeyDrivers, i, DriverNameW, sizeof(DriverNameW))
|
|
|
|
!= ERROR_SUCCESS) {
|
|
|
|
ERR("Can't enum key number %ld\n", i);
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(!WINSPOOL_GetDriverInfoFromReg(hkeyDrivers, DriverNameW,
|
|
|
|
pEnvironment, Level, ptr,
|
|
|
|
(cbBuf < *pcbNeeded) ? NULL : pDriverInfo + *pcbNeeded,
|
|
|
|
(cbBuf < *pcbNeeded) ? 0 : cbBuf - *pcbNeeded,
|
|
|
|
&needed, unicode)) {
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
(*pcbNeeded) += needed;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hkeyDrivers);
|
|
|
|
|
|
|
|
if(cbBuf < *pcbNeeded){
|
|
|
|
SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* EnumPrinterDriversW [WINSPOOL.173]
|
|
|
|
*
|
|
|
|
* see function EnumPrinterDrivers for RETURNS, BUGS
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumPrinterDriversW(LPWSTR pName, LPWSTR pEnvironment, DWORD Level,
|
|
|
|
LPBYTE pDriverInfo, DWORD cbBuf,
|
|
|
|
LPDWORD pcbNeeded, LPDWORD pcReturned)
|
|
|
|
{
|
|
|
|
return WINSPOOL_EnumPrinterDrivers(pName, pEnvironment, Level, pDriverInfo,
|
|
|
|
cbBuf, pcbNeeded, pcReturned, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* EnumPrinterDriversA [WINSPOOL.172]
|
|
|
|
*
|
|
|
|
* see function EnumPrinterDrivers for RETURNS, BUGS
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumPrinterDriversA(LPSTR pName, LPSTR pEnvironment, DWORD Level,
|
|
|
|
LPBYTE pDriverInfo, DWORD cbBuf,
|
|
|
|
LPDWORD pcbNeeded, LPDWORD pcReturned)
|
|
|
|
{ BOOL ret;
|
|
|
|
WCHAR *pNameW = NULL, *pEnvironmentW = NULL;
|
|
|
|
|
|
|
|
if(pName)
|
|
|
|
pNameW = HEAP_strdupAtoW(GetProcessHeap(), 0, pName);
|
|
|
|
if(pEnvironment)
|
|
|
|
pEnvironmentW = HEAP_strdupAtoW(GetProcessHeap(), 0, pEnvironment);
|
|
|
|
|
|
|
|
ret = WINSPOOL_EnumPrinterDrivers(pNameW, pEnvironmentW, Level, pDriverInfo,
|
|
|
|
cbBuf, pcbNeeded, pcReturned, FALSE);
|
|
|
|
if(pNameW)
|
|
|
|
HeapFree(GetProcessHeap(), 0, pNameW);
|
|
|
|
if(pEnvironmentW)
|
|
|
|
HeapFree(GetProcessHeap(), 0, pEnvironmentW);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2000-11-28 23:33:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* EnumPortsA (WINSPOOL.166)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI EnumPortsA(LPSTR name,DWORD level,LPBYTE ports,DWORD bufsize,
|
|
|
|
LPDWORD bufneeded,LPDWORD bufreturned)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%ld,%p,%ld,%p,%p), stub!\n",name,level,ports,bufsize,bufneeded,bufreturned);
|
|
|
|
return FALSE;
|
|
|
|
}
|