reactos/win32ss/printing/base/winspool/utils.c
Joachim Henze 818e5bc752 [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
acec69a1d7

[WINSPOOL] Add Implementation of EnumPrintersA (#2273)
cherry picked from commit 0.4.14-dev-878-g
e8b177825b

[FORMATTING] Fix indentation of winspool/printers.c
No code changes
cherry picked from commit 0.4.14-dev-879-g
45f39ffc25

[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
adffa8ea75

[WINSPOOL] printers.c: Demote 3 ERR() to TRACE(), Fix 1 copypasta (#2311)
cherry picked from commit 0.4.14-dev-889-g
06f8f80181

[WINSPOOL] Implement GetPrinterDriverA and a helper function UnicodeToAnsiInPlace (#2317)
cherry picked from commit 0.4.14-dev-957-g
d90beaeed2

[WINSPOOL] Fix build
cherry picked from commit 0.4.14-dev-958-g
8da7fbc704

[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
5d8c39753e

[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
3077c0e43e
2020-02-27 03:02:21 +01:00

56 lines
1.6 KiB
C

/*
* 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;
}