reactos/win32ss/printing/base/winspool/utils.c

56 lines
1.6 KiB
C
Raw Normal View History

[0.4.13][PRINTING] Fix regression CORE-16622 in comdlg32:printdlg ANSI A very nice set of patches done by Doug Lyons!, Jim Tabor, Colin Finck to fix: - a crash on the testbots for comdlg32:printdlg - erroneous behavior of PrintDlg in _A()-application "Kompozer", namely - prevents exceptions from being thrown when opening the print dlg - prevents heap allocations of 0 byte size when opening the print dlg - prevents a help-button that should be invisible from overlapping other controls - allows Kompozer to extend the print-dialog with additional controls - allows combobox to show the printers name, instead of memory garbage [PRINTING] Improve Stubs for GetPrinterA and GetPrinterDeviceA (#2274) cherry picked from commit 0.4.14-dev-849-g acec69a1d7333dfc8b0a1e922196b29768ce0f9c [WINSPOOL] Add Implementation of EnumPrintersA (#2273) cherry picked from commit 0.4.14-dev-878-g e8b177825b0f44784286032d6ec64606c7b0a718 [FORMATTING] Fix indentation of winspool/printers.c No code changes cherry picked from commit 0.4.14-dev-879-g 45f39ffc253012b2399dc1105bcb797caec6ae36 [PRINTING] Part of GDI Support Fix ups and added support to prevent GDI from crashing. These functions will be required for GDI. Part 1 of print support. cherry picked from commit 0.4.14-dev-880-g adffa8ea7591f4d2d6530a82361d419a9ffc8ad7 [WINSPOOL] printers.c: Demote 3 ERR() to TRACE(), Fix 1 copypasta (#2311) cherry picked from commit 0.4.14-dev-889-g 06f8f8018191a15714d27b78f3d1e38eb1623e37 [WINSPOOL] Implement GetPrinterDriverA and a helper function UnicodeToAnsiInPlace (#2317) cherry picked from commit 0.4.14-dev-957-g d90beaeed26863985486874aaa2a1c3422fd6d9f [WINSPOOL] Fix build cherry picked from commit 0.4.14-dev-958-g 8da7fbc704448a03610a5497a88f9dfada8be644 [GDI32] GdiConvertToDevmodeW: Import WINE commit 32393796bb534e9cf11dd988dce88722c67f7906 ("gdi32: GdiConvertToDevmodeW should not refer to unintialized name bytes.") This makes our GdiConvertToDevmodeW equivalent to the WINE counterpart again. cherry picked from commit 0.4.14-dev-1031-g 5d8c39753e82e8e7f8db90a427b230ed248f0158 [WINSPOOL] Implement DocumentPropertiesA including DEVMODE conversions (#2339) Co-authored-by: Doug Lyons <douglyons@douglyons.com> Co-authored-by: Colin Finck <colin@reactos.org> cherry picked from commit 0.4.14-dev-1035-g 3077c0e43e08bc98f801718a86d354adc269a963
2020-02-26 22:21:00 +00:00
/*
* PROJECT: ReactOS Spooler API
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Utility Functions related to Print Processors
* COPYRIGHT: Copyright 2020 Doug Lyons (douglyons@douglyons.com)
*/
#include "precomp.h"
BOOL UnicodeToAnsiInPlace(PWSTR pwszField)
{
/*
* This converts an incoming Unicode string to an ANSI string.
* It returns FALSE on failure, otherwise it returns TRUE.
* It is only useful for "in-place" conversions where the ANSI string goes
* back into the same place where the Unicode string came into this function.
* It seems that many of the functions involving printing can use this.
*/
PSTR pszTemp;
DWORD cch;
/*
* Map the incoming Unicode pwszField string to an ANSI one here so that we can do
* in-place conversion. We read the Unicode input and then we write back the ANSI
* conversion into the same buffer for use with our GetPrinterDriverA function
*/
PSTR pszField = (PSTR)pwszField;
if (!pwszField)
{
return TRUE;
}
cch = wcslen(pwszField);
if (cch == 0)
{
return TRUE;
}
pszTemp = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(CHAR));
if (!pszField)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
ERR("HeapAlloc failed!\n");
return FALSE; // indicates a failure to be handled by caller
}
WideCharToMultiByte(CP_ACP, 0, pwszField, -1, pszTemp, cch + 1, NULL, NULL);
StringCchCopyA(pszField, cch + 1, pszTemp);
HeapFree(hProcessHeap, 0, pszTemp);
return TRUE;
}