2015-07-22 17:59:46 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Spooler API
|
2017-09-29 17:18:19 +00:00
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
2015-07-22 17:59:46 +00:00
|
|
|
* PURPOSE: Functions related to Printer Configuration Data
|
2017-09-29 17:18:19 +00:00
|
|
|
* COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
|
2015-07-22 17:59:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2020-08-04 02:07:58 +00:00
|
|
|
LONG WINAPI
|
|
|
|
AdvancedSetupDialog(HWND hWnd, INT Unknown, PDEVMODEA pDevModeInput, PDEVMODEA pDevModeOutput)
|
|
|
|
{
|
|
|
|
HANDLE hPrinter;
|
|
|
|
LONG Ret = -1;
|
|
|
|
|
|
|
|
TRACE("AdvancedSetupDialog(%p, %d, %p, %p)\n", hWnd, Unknown, pDevModeOutput, pDevModeInput);
|
|
|
|
|
|
|
|
if ( OpenPrinterA( (LPSTR)pDevModeInput->dmDeviceName, &hPrinter, NULL ) )
|
|
|
|
{
|
|
|
|
Ret = AdvancedDocumentPropertiesA( hWnd, hPrinter, (PSTR)pDevModeInput->dmDeviceName, pDevModeOutput, pDevModeInput );
|
|
|
|
ClosePrinter(hPrinter);
|
|
|
|
}
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
LONG WINAPI
|
|
|
|
AdvancedDocumentPropertiesA(HWND hWnd, HANDLE hPrinter, PSTR pDeviceName, PDEVMODEA pDevModeOutput, PDEVMODEA pDevModeInput)
|
|
|
|
{
|
|
|
|
TRACE("AdvancedDocumentPropertiesA(%p, %p, %s, %p, %p)\n", hWnd, hPrinter, pDeviceName, pDevModeOutput, pDevModeInput);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-22 17:59:46 +00:00
|
|
|
LONG WINAPI
|
|
|
|
AdvancedDocumentPropertiesW(HWND hWnd, HANDLE hPrinter, PWSTR pDeviceName, PDEVMODEW pDevModeOutput, PDEVMODEW pDevModeInput)
|
|
|
|
{
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("AdvancedDocumentPropertiesW(%p, %p, %S, %p, %p)\n", hWnd, hPrinter, pDeviceName, pDevModeOutput, pDevModeInput);
|
2015-07-22 17:59:46 +00:00
|
|
|
UNIMPLEMENTED;
|
2017-12-09 12:35:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
DeletePrinterDataA(HANDLE hPrinter, PSTR pValueName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
LPWSTR valuenameW = NULL;
|
|
|
|
INT len;
|
|
|
|
DWORD res;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("DeletePrinterDataA(%p, %s)\n", hPrinter, pValueName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
if (pValueName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pValueName, -1, NULL, 0);
|
|
|
|
valuenameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pValueName, -1, valuenameW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = DeletePrinterDataW( hPrinter, valuenameW );
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
if (valuenameW) HeapFree(GetProcessHeap(), 0, valuenameW);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
DeletePrinterDataExA(HANDLE hPrinter, PCSTR pKeyName, PCSTR pValueName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
LPWSTR keynameW = NULL;
|
|
|
|
LPWSTR valuenameW = NULL;
|
|
|
|
INT len;
|
|
|
|
DWORD res;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("DeletePrinterDataExA(%p, %s, %s)\n", hPrinter, pKeyName, pValueName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
if (pKeyName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pKeyName, -1, NULL, 0);
|
|
|
|
keynameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pKeyName, -1, keynameW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pValueName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pValueName, -1, NULL, 0);
|
|
|
|
valuenameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pValueName, -1, valuenameW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = DeletePrinterDataExW( hPrinter, keynameW, valuenameW );
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
if (keynameW) HeapFree(GetProcessHeap(), 0, keynameW);
|
|
|
|
if (valuenameW) HeapFree(GetProcessHeap(), 0, valuenameW);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
return res;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
DeletePrinterDataExW(HANDLE hPrinter, PCWSTR pKeyName, PCWSTR pValueName)
|
|
|
|
{
|
|
|
|
TRACE("DeletePrinterDataExW(%p, %S, %S)\n", hPrinter, pKeyName, pValueName);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
DeletePrinterDataW(HANDLE hPrinter, PWSTR pValueName)
|
|
|
|
{
|
|
|
|
TRACE("DeletePrinterDataW(%p, %S)\n", hPrinter, pValueName);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
DeletePrinterKeyA(HANDLE hPrinter, PCSTR pKeyName)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
LPWSTR keynameW = NULL;
|
|
|
|
INT len;
|
|
|
|
DWORD res;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("DeletePrinterKeyA(%p, %s)\n", hPrinter, pKeyName);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
if (pKeyName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, pKeyName, -1, NULL, 0);
|
|
|
|
keynameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pKeyName, -1, keynameW, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
res = DeletePrinterKeyW( hPrinter, keynameW );
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
if (keynameW) HeapFree(GetProcessHeap(), 0, keynameW);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
return res;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
DeletePrinterKeyW(HANDLE hPrinter, PCWSTR pKeyName)
|
|
|
|
{
|
|
|
|
TRACE("DeletePrinterKeyW(%p, %S)\n", hPrinter, pKeyName);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
EnumPrinterDataA(HANDLE hPrinter, DWORD dwIndex, PSTR pValueName, DWORD cbValueName, PDWORD pcbValueName, PDWORD pType, PBYTE pData, DWORD cbData, PDWORD pcbData)
|
|
|
|
{
|
|
|
|
TRACE("EnumPrinterDataA(%p, %lu, %s, %lu, %p, %p, %p, %lu, %p)\n", hPrinter, dwIndex, pValueName, cbValueName, pcbValueName, pType, pData, cbData, pcbData);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
EnumPrinterDataExA(HANDLE hPrinter, PCSTR pKeyName, PBYTE pEnumValues, DWORD cbEnumValues, PDWORD pcbEnumValues, PDWORD pnEnumValues)
|
|
|
|
{
|
2020-08-04 02:07:58 +00:00
|
|
|
INT len;
|
|
|
|
LPWSTR pKeyNameW;
|
|
|
|
DWORD ret, dwIndex, dwBufSize;
|
|
|
|
HANDLE hHeap;
|
|
|
|
LPSTR pBuffer;
|
|
|
|
|
2017-12-09 12:35:42 +00:00
|
|
|
TRACE("EnumPrinterDataExA(%p, %s, %p, %lu, %p, %p)\n", hPrinter, pKeyName, pEnumValues, cbEnumValues, pcbEnumValues, pnEnumValues);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
if (pKeyName == NULL || *pKeyName == 0)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
len = MultiByteToWideChar (CP_ACP, 0, pKeyName, -1, NULL, 0);
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
ret = GetLastError ();
|
|
|
|
ERR ("MultiByteToWideChar failed with code %i\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
hHeap = GetProcessHeap ();
|
|
|
|
if (hHeap == NULL)
|
|
|
|
{
|
|
|
|
ERR ("GetProcessHeap failed\n");
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
pKeyNameW = HeapAlloc (hHeap, 0, len * sizeof (WCHAR));
|
|
|
|
if (pKeyNameW == NULL)
|
|
|
|
{
|
|
|
|
ERR ("Failed to allocate %i bytes from process heap\n",
|
|
|
|
(LONG)(len * sizeof (WCHAR)));
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MultiByteToWideChar (CP_ACP, 0, pKeyName, -1, pKeyNameW, len) == 0)
|
|
|
|
{
|
|
|
|
ret = GetLastError ();
|
|
|
|
ERR ("MultiByteToWideChar failed with code %i\n", ret);
|
|
|
|
if (HeapFree (hHeap, 0, pKeyNameW) == 0)
|
|
|
|
WARN ("HeapFree failed with code %i\n", GetLastError ());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = EnumPrinterDataExW (hPrinter, pKeyNameW, pEnumValues, cbEnumValues, pcbEnumValues, pnEnumValues);
|
|
|
|
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
if (HeapFree (hHeap, 0, pKeyNameW) == 0)
|
|
|
|
WARN ("HeapFree failed with code %i\n", GetLastError ());
|
|
|
|
TRACE ("EnumPrinterDataExW returned %i\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HeapFree (hHeap, 0, pKeyNameW) == 0)
|
|
|
|
{
|
|
|
|
ret = GetLastError ();
|
|
|
|
ERR ("HeapFree failed with code %i\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pnEnumValues == 0) /* empty key */
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
dwBufSize = 0;
|
|
|
|
for (dwIndex = 0; dwIndex < *pnEnumValues; ++dwIndex)
|
|
|
|
{
|
2020-08-26 22:12:20 +00:00
|
|
|
PPRINTER_ENUM_VALUESW ppev = &((PPRINTER_ENUM_VALUESW) pEnumValues)[dwIndex];
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
if (dwBufSize < ppev->cbValueName)
|
|
|
|
dwBufSize = ppev->cbValueName;
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
if ( dwBufSize < ppev->cbData &&
|
|
|
|
(ppev->dwType == REG_SZ || ppev->dwType == REG_EXPAND_SZ || ppev->dwType == REG_MULTI_SZ))
|
2020-08-04 02:07:58 +00:00
|
|
|
dwBufSize = ppev->cbData;
|
|
|
|
}
|
|
|
|
|
2020-08-26 22:12:20 +00:00
|
|
|
FIXME ("Largest Unicode name or value is %i bytes\n", dwBufSize);
|
2020-08-04 02:07:58 +00:00
|
|
|
|
|
|
|
pBuffer = HeapAlloc (hHeap, 0, dwBufSize);
|
|
|
|
if (pBuffer == NULL)
|
|
|
|
{
|
|
|
|
ERR ("Failed to allocate %i bytes from process heap\n", dwBufSize);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (dwIndex = 0; dwIndex < *pnEnumValues; ++dwIndex)
|
|
|
|
{
|
|
|
|
PPRINTER_ENUM_VALUESW ppev =
|
|
|
|
&((PPRINTER_ENUM_VALUESW) pEnumValues)[dwIndex];
|
|
|
|
|
|
|
|
len = WideCharToMultiByte (CP_ACP, 0, ppev->pValueName,
|
|
|
|
ppev->cbValueName / sizeof (WCHAR), pBuffer, dwBufSize, NULL,
|
|
|
|
NULL);
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
ret = GetLastError ();
|
|
|
|
ERR ("WideCharToMultiByte failed with code %i\n", ret);
|
|
|
|
if (HeapFree (hHeap, 0, pBuffer) == 0)
|
|
|
|
WARN ("HeapFree failed with code %i\n", GetLastError ());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (ppev->pValueName, pBuffer, len);
|
|
|
|
|
|
|
|
TRACE ("Converted '%s' from Unicode to ASCII\n", pBuffer);
|
|
|
|
|
|
|
|
if (ppev->dwType != REG_SZ && ppev->dwType != REG_EXPAND_SZ &&
|
|
|
|
ppev->dwType != REG_MULTI_SZ)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = WideCharToMultiByte (CP_ACP, 0, (LPWSTR) ppev->pData,
|
|
|
|
ppev->cbData / sizeof (WCHAR), pBuffer, dwBufSize, NULL, NULL);
|
|
|
|
if (len == 0)
|
|
|
|
{
|
|
|
|
ret = GetLastError ();
|
|
|
|
ERR ("WideCharToMultiByte failed with code %i\n", ret);
|
|
|
|
if (HeapFree (hHeap, 0, pBuffer) == 0)
|
|
|
|
WARN ("HeapFree failed with code %i\n", GetLastError ());
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (ppev->pData, pBuffer, len);
|
|
|
|
|
|
|
|
TRACE ("Converted '%s' from Unicode to ASCII\n", pBuffer);
|
|
|
|
TRACE (" (only first string of REG_MULTI_SZ printed)\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HeapFree (hHeap, 0, pBuffer) == 0)
|
|
|
|
{
|
|
|
|
ret = GetLastError ();
|
|
|
|
ERR ("HeapFree failed with code %i\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2017-12-09 12:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
EnumPrinterDataExW(HANDLE hPrinter, PCWSTR pKeyName, PBYTE pEnumValues, DWORD cbEnumValues, PDWORD pcbEnumValues, PDWORD pnEnumValues)
|
|
|
|
{
|
|
|
|
TRACE("EnumPrinterDataExW(%p, %S, %p, %lu, %p, %p)\n", hPrinter, pKeyName, pEnumValues, cbEnumValues, pcbEnumValues, pnEnumValues);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
EnumPrinterDataW(HANDLE hPrinter, DWORD dwIndex, PWSTR pValueName, DWORD cbValueName, PDWORD pcbValueName, PDWORD pType, PBYTE pData, DWORD cbData, PDWORD pcbData)
|
|
|
|
{
|
|
|
|
TRACE("EnumPrinterDataW(%p, %lu, %S, %lu, %p, %p, %p, %lu, %p)\n", hPrinter, dwIndex, pValueName, cbValueName, pcbValueName, pType, pData, cbData, pcbData);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
EnumPrinterKeyA(HANDLE hPrinter, PCSTR pKeyName, PSTR pSubkey, DWORD cbSubkey, PDWORD pcbSubkey)
|
|
|
|
{
|
|
|
|
TRACE("EnumPrinterKeyA(%p, %s, %s, %lu, %p)\n", hPrinter, pKeyName, pSubkey, cbSubkey, pcbSubkey);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
EnumPrinterKeyW(HANDLE hPrinter, PCWSTR pKeyName, PWSTR pSubkey, DWORD cbSubkey, PDWORD pcbSubkey)
|
|
|
|
{
|
|
|
|
TRACE("EnumPrinterKeyW(%p, %S, %S, %lu, %p)\n", hPrinter, pKeyName, pSubkey, cbSubkey, pcbSubkey);
|
|
|
|
UNIMPLEMENTED;
|
|
|
|
return ERROR_NOT_SUPPORTED;
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
GetPrinterDataA(HANDLE hPrinter, LPSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
|
2015-07-22 17:59:46 +00:00
|
|
|
{
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("GetPrinterDataA(%p, %s, %p, %p, %lu, %p)\n", hPrinter, pValueName, pType, pData, nSize, pcbNeeded);
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
return GetPrinterDataExA(hPrinter, "PrinterDriverData", pValueName, pType, pData, nSize, pcbNeeded);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
GetPrinterDataExA(HANDLE hPrinter, LPCSTR pKeyName, LPCSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
DWORD cbUnicodeData;
|
|
|
|
DWORD cch;
|
|
|
|
DWORD dwReturnValue;
|
|
|
|
DWORD dwType;
|
|
|
|
POSVERSIONINFOEXA pInfoA;
|
|
|
|
POSVERSIONINFOEXW pInfoW;
|
|
|
|
PVOID pUnicodeData = NULL;
|
|
|
|
PWSTR pwszKeyName = NULL;
|
|
|
|
PWSTR pwszValueName = NULL;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("GetPrinterDataExA(%p, %s, %s, %p, %p, %lu, %p)\n", hPrinter, pKeyName, pValueName, pType, pData, nSize, pcbNeeded);
|
|
|
|
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
if (pKeyName)
|
|
|
|
{
|
|
|
|
// Convert pKeyName to a Unicode string pwszKeyName
|
|
|
|
cch = strlen(pKeyName);
|
|
|
|
|
|
|
|
pwszKeyName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszKeyName)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("HeapAlloc failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pKeyName, -1, pwszKeyName, cch + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pValueName)
|
|
|
|
{
|
|
|
|
// Convert pValueName to a Unicode string pwszValueName
|
|
|
|
cch = strlen(pValueName);
|
|
|
|
|
|
|
|
pwszValueName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszValueName)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("HeapAlloc failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pValueName, -1, pwszValueName, cch + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need the data type information, even if no pData was passed.
|
|
|
|
if (!pType)
|
|
|
|
pType = &dwType;
|
|
|
|
|
|
|
|
// Call GetPrinterDataExW for the first time.
|
|
|
|
// If we're lucky, the supplied buffer is already large enough and we don't need to do the expensive RPC call a second time.
|
|
|
|
dwReturnValue = GetPrinterDataExW(hPrinter, pwszKeyName, pwszValueName, pType, pData, nSize, pcbNeeded);
|
|
|
|
|
|
|
|
// If a critical error occurred, just return it. We cannot do anything else in this case.
|
|
|
|
if (dwReturnValue != ERROR_SUCCESS && dwReturnValue != ERROR_MORE_DATA)
|
|
|
|
goto Cleanup;
|
|
|
|
|
|
|
|
// Save the needed buffer size for the Unicode data. We may alter *pcbNeeded for an ANSI buffer size.
|
|
|
|
cbUnicodeData = *pcbNeeded;
|
|
|
|
|
|
|
|
if (*pType == REG_SZ || *pType == REG_MULTI_SZ || *pType == REG_EXPAND_SZ)
|
|
|
|
{
|
|
|
|
// This is a string that needs to be converted from Unicode to ANSI.
|
|
|
|
// Output the required buffer size for the ANSI string.
|
|
|
|
*pcbNeeded /= sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else if (*pType == REG_NONE)
|
|
|
|
{
|
|
|
|
if (cbUnicodeData == sizeof(OSVERSIONINFOW) && wcsicmp(pwszValueName, SPLREG_OS_VERSION) == 0)
|
|
|
|
{
|
|
|
|
// This is a Unicode OSVERSIONINFOW structure that needs to be converted to an ANSI OSVERSIONINFOA.
|
|
|
|
*pcbNeeded = sizeof(OSVERSIONINFOA);
|
|
|
|
}
|
|
|
|
else if (cbUnicodeData == sizeof(OSVERSIONINFOEXW) && wcsicmp(pwszValueName, SPLREG_OS_VERSIONEX) == 0)
|
|
|
|
{
|
|
|
|
// This is a Unicode OSVERSIONINFOEXW structure that needs to be converted to an ANSI OSVERSIONINFOEXA.
|
|
|
|
*pcbNeeded = sizeof(OSVERSIONINFOEXA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Other REG_NONE value, nothing to do.
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the supplied buffer is large enough for the ANSI data.
|
|
|
|
if (nSize < *pcbNeeded)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_MORE_DATA;
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate a temporary buffer for the Unicode data.
|
|
|
|
pUnicodeData = HeapAlloc(hProcessHeap, 0, cbUnicodeData);
|
|
|
|
if (!pUnicodeData)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("HeapAlloc failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dwReturnValue == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
// ERROR_SUCCESS: The buffer is large enough for the ANSI and the Unicode string,
|
|
|
|
// so the Unicode string has been copied into pData. Copy it to pUnicodeData.
|
|
|
|
CopyMemory(pUnicodeData, pData, cbUnicodeData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ERROR_MORE_DATA: The buffer is large enough for the ANSI string, but not for the Unicode string.
|
|
|
|
// We have to call GetPrinterDataExW again with the temporary buffer.
|
|
|
|
dwReturnValue = GetPrinterDataExW(hPrinter, pwszKeyName, pwszValueName, NULL, (PBYTE)pUnicodeData, cbUnicodeData, &cbUnicodeData);
|
|
|
|
if (dwReturnValue != ERROR_SUCCESS)
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*pType == REG_SZ || *pType == REG_MULTI_SZ || *pType == REG_EXPAND_SZ)
|
|
|
|
{
|
|
|
|
// Convert the Unicode string to ANSI.
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, (PWSTR)pUnicodeData, -1, (PSTR)pData, *pcbNeeded, NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is a REG_NONE with either OSVERSIONINFOW or OSVERSIONINFOEXW.
|
|
|
|
// Copy the fields and convert the Unicode CSD Version string to ANSI.
|
|
|
|
pInfoW = (POSVERSIONINFOEXW)pUnicodeData;
|
|
|
|
pInfoA = (POSVERSIONINFOEXA)pData;
|
|
|
|
pInfoA->dwMajorVersion = pInfoW->dwMajorVersion;
|
|
|
|
pInfoA->dwMinorVersion = pInfoW->dwMinorVersion;
|
|
|
|
pInfoA->dwBuildNumber = pInfoW->dwBuildNumber;
|
|
|
|
pInfoA->dwPlatformId = pInfoW->dwPlatformId;
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, pInfoW->szCSDVersion, -1, pInfoA->szCSDVersion, sizeof(pInfoA->szCSDVersion), NULL, NULL);
|
|
|
|
|
|
|
|
if (cbUnicodeData == sizeof(OSVERSIONINFOW))
|
|
|
|
{
|
|
|
|
pInfoA->dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pInfoA->dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA);
|
|
|
|
pInfoA->wServicePackMajor = pInfoW->wServicePackMajor;
|
|
|
|
pInfoA->wServicePackMinor = pInfoW->wServicePackMinor;
|
|
|
|
pInfoA->wSuiteMask = pInfoW->wSuiteMask;
|
|
|
|
pInfoA->wProductType = pInfoW->wProductType;
|
|
|
|
pInfoA->wReserved = pInfoW->wReserved;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
if (pwszKeyName)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszKeyName);
|
|
|
|
|
|
|
|
if (pwszValueName)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszValueName);
|
|
|
|
|
|
|
|
if (pUnicodeData)
|
|
|
|
HeapFree(hProcessHeap, 0, pUnicodeData);
|
|
|
|
|
|
|
|
return dwReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
GetPrinterDataExW(HANDLE hPrinter, LPCWSTR pKeyName, LPCWSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
|
|
|
|
{
|
|
|
|
const WCHAR wszEmptyString[] = L"";
|
|
|
|
|
|
|
|
BYTE DummyData;
|
|
|
|
DWORD dwErrorCode;
|
|
|
|
DWORD dwType = REG_NONE;
|
|
|
|
PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("GetPrinterDataExW(%p, %S, %S, %p, %p, %lu, %p)\n", hPrinter, pKeyName, pValueName, pType, pData, nSize, pcbNeeded);
|
|
|
|
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
// Sanity checks
|
|
|
|
if (!pHandle)
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
// Yes, instead of declaring these pointers unique in the IDL file (and perfectly accepting NULL pointers this way),
|
|
|
|
// Windows does it differently for GetPrinterDataExW and points them to empty variables.
|
|
|
|
if (!pKeyName)
|
|
|
|
pKeyName = wszEmptyString;
|
|
|
|
|
|
|
|
if (!pType)
|
|
|
|
pType = &dwType;
|
|
|
|
|
|
|
|
if (!pData && !nSize)
|
|
|
|
pData = &DummyData;
|
|
|
|
|
|
|
|
// Do the RPC call
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcGetPrinterDataEx(pHandle->hPrinter, pKeyName, pValueName, pType, pData, nSize, pcbNeeded);
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
|
|
|
return dwErrorCode;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
GetPrinterDataW(HANDLE hPrinter, LPWSTR pValueName, LPDWORD pType, LPBYTE pData, DWORD nSize, LPDWORD pcbNeeded)
|
|
|
|
{
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("GetPrinterDataW(%p, %S, %p, %p, %lu, %p)\n", hPrinter, pValueName, pType, pData, nSize, pcbNeeded);
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
return GetPrinterDataExW(hPrinter, L"PrinterDriverData", pValueName, pType, pData, nSize, pcbNeeded);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
SetPrinterDataA(HANDLE hPrinter, PSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
|
|
|
|
{
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("SetPrinterDataA(%p, %s, %lu, %p, %lu)\n", hPrinter, pValueName, Type, pData, cbData);
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
return SetPrinterDataExA(hPrinter, "PrinterDriverData", pValueName, Type, pData, cbData);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
SetPrinterDataExA(HANDLE hPrinter, LPCSTR pKeyName, LPCSTR pValueName, DWORD Type, LPBYTE pData, DWORD cbData)
|
|
|
|
{
|
|
|
|
DWORD cch;
|
|
|
|
DWORD dwReturnValue;
|
|
|
|
PWSTR pwszKeyName = NULL;
|
|
|
|
PWSTR pwszValueName = NULL;
|
|
|
|
PWSTR pUnicodeData = NULL;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("SetPrinterDataExA(%p, %s, %s, %lu, %p, %lu)\n", hPrinter, pKeyName, pValueName, Type, pData, cbData);
|
|
|
|
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
if (pKeyName)
|
|
|
|
{
|
|
|
|
// Convert pKeyName to a Unicode string pwszKeyName
|
|
|
|
cch = strlen(pKeyName);
|
|
|
|
|
|
|
|
pwszKeyName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszKeyName)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("HeapAlloc failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pKeyName, -1, pwszKeyName, cch + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pValueName)
|
|
|
|
{
|
|
|
|
// Convert pValueName to a Unicode string pwszValueName
|
|
|
|
cch = strlen(pValueName);
|
|
|
|
|
|
|
|
pwszValueName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
|
|
|
|
if (!pwszValueName)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("HeapAlloc failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pValueName, -1, pwszValueName, cch + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Type == REG_SZ || Type == REG_MULTI_SZ || Type == REG_EXPAND_SZ)
|
|
|
|
{
|
|
|
|
// Convert pData to a Unicode string pUnicodeData.
|
|
|
|
pUnicodeData = HeapAlloc(hProcessHeap, 0, cbData * sizeof(WCHAR));
|
|
|
|
if (!pUnicodeData)
|
|
|
|
{
|
|
|
|
dwReturnValue = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
ERR("HeapAlloc failed!\n");
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (PCSTR)pData, -1, pUnicodeData, cbData);
|
|
|
|
|
|
|
|
pData = (PBYTE)pUnicodeData;
|
|
|
|
cbData *= sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
dwReturnValue = SetPrinterDataExW(hPrinter, pwszKeyName, pwszValueName, Type, pData, cbData);
|
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
if (pwszKeyName)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszKeyName);
|
|
|
|
|
|
|
|
if (pwszValueName)
|
|
|
|
HeapFree(hProcessHeap, 0, pwszValueName);
|
|
|
|
|
|
|
|
if (pUnicodeData)
|
|
|
|
HeapFree(hProcessHeap, 0, pUnicodeData);
|
|
|
|
|
|
|
|
return dwReturnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
SetPrinterDataExW(HANDLE hPrinter, LPCWSTR pKeyName, LPCWSTR pValueName, DWORD Type, LPBYTE pData, DWORD cbData)
|
|
|
|
{
|
|
|
|
const WCHAR wszEmptyString[] = L"";
|
|
|
|
|
|
|
|
DWORD dwErrorCode;
|
|
|
|
PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
|
|
|
|
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("SetPrinterDataExW(%p, %S, %S, %lu, %p, %lu)\n", hPrinter, pKeyName, pValueName, Type, pData, cbData);
|
|
|
|
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
// Sanity checks
|
|
|
|
if (!pHandle)
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
if (!pKeyName)
|
|
|
|
pKeyName = wszEmptyString;
|
|
|
|
|
|
|
|
// Do the RPC call
|
|
|
|
RpcTryExcept
|
|
|
|
{
|
|
|
|
dwErrorCode = _RpcSetPrinterDataEx(pHandle->hPrinter, pKeyName, pValueName, Type, pData, cbData);
|
|
|
|
}
|
|
|
|
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
dwErrorCode = RpcExceptionCode();
|
|
|
|
}
|
|
|
|
RpcEndExcept;
|
|
|
|
|
|
|
|
return dwErrorCode;
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI
|
|
|
|
SetPrinterDataW(HANDLE hPrinter, PWSTR pValueName, DWORD Type, PBYTE pData, DWORD cbData)
|
|
|
|
{
|
2017-12-09 11:00:09 +00:00
|
|
|
TRACE("SetPrinterDataW(%p, %S, %lu, %p, %lu)\n", hPrinter, pValueName, Type, pData, cbData);
|
[PRINTING]
- Implement GetPrinterDataA, GetPrinterDataExA, GetPrinterDataExW, GetPrinterDataW, SetPrinterDataA, SetPrinterDataExA, SetPrinterDataExW, SetPrinterDataW.
They support all features for Print Server and Printer Handles (minus security checks!)
I've also added tests for them.
- Store Printer data in SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers instead of SYSTEM\CurrentControlSet\Control\Print\Printers and create a registry symlink from the former path to the new one just like Windows does.
According to https://social.technet.microsoft.com/Forums/windowsserver/en-US/a683ab54-c43c-4ebe-af8f-1f7a65af2a51, this is needed when having >900 printers to work around a size limit of the SYSTEM registry hive. And if Windows has both locations, we need both for compatibility anyway.
- Add several settings which are queried by the new Printer Data APIs when working with Print Server Handles.
- Store the job directory in the Windows-compatible "DefaultSpoolDirectory" setting and make use of it.
- Revert the ASSERTs in LocalEnumPrinters again to let us verify the NULL pointer exceptions in localspl_apitest (thanks Serge! CORE-13433)
- Translate ERROR_INVALID_NAME to ERROR_INVALID_PRINTER_NAME in all cases in OpenPrinterW (thanks Victor! CORE-13412)
- Make EnumMonitorsW and EnumPortsW in spoolss more robust against failing Print Monitors.
- Remove the wrong !phPrinter check in OpenPrinterW to make Print Server Handles work for real.
- Fix error handling when memory allocation fails: HeapAlloc doesn't set last error, so it's just wrong to query or return it.
One more item done from https://reactos.org/wiki/Printing !
This is all still a big Work-in-Progress, with many subtle bugs deep down in ReactOS, for which I need to open additional tickets. But I didn't want to make this commit even bigger..
svn path=/trunk/; revision=75125
2017-06-19 14:18:19 +00:00
|
|
|
return SetPrinterDataExW(hPrinter, L"PrinterDriverData", pValueName, Type, pData, cbData);
|
2015-07-22 17:59:46 +00:00
|
|
|
}
|