ReactOS  0.4.14-dev-1256-g2125fec
tools.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Local Spooler
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE: Various tools
5  * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6  */
7 
8 #include "precomp.h"
9 
25 PWSTR
27 {
28  DWORD cbNeeded;
29  LONG lStatus;
30  PWSTR pwszValue;
31 
32  // Determine the size of the required buffer.
33  lStatus = RegQueryValueExW(hKey, pwszValueName, NULL, NULL, NULL, &cbNeeded);
34  if (lStatus != ERROR_SUCCESS)
35  {
36  ERR("RegQueryValueExW failed with status %ld!\n", lStatus);
37  return NULL;
38  }
39 
40  // Allocate it.
41  pwszValue = DllAllocSplMem(cbNeeded);
42  if (!pwszValue)
43  {
44  ERR("DllAllocSplMem failed!\n");
45  return NULL;
46  }
47 
48  // Now get the actual value.
49  lStatus = RegQueryValueExW(hKey, pwszValueName, NULL, NULL, (PBYTE)pwszValue, &cbNeeded);
50  if (lStatus != ERROR_SUCCESS)
51  {
52  ERR("RegQueryValueExW failed with status %ld!\n", lStatus);
53  DllFreeSplMem(pwszValue);
54  return NULL;
55  }
56 
57  return pwszValue;
58 }
59 
62 {
63  PDEVMODEW pOutput;
64 
65  // Allocate a buffer for this DevMode.
66  pOutput = DllAllocSplMem(pInput->dmSize + pInput->dmDriverExtra);
67  if (!pOutput)
68  {
69  ERR("DllAllocSplMem failed!\n");
70  return NULL;
71  }
72 
73  // Copy it.
74  CopyMemory(pOutput, pInput, pInput->dmSize + pInput->dmDriverExtra);
75 
76  return pOutput;
77 }
const uint16_t * PCWSTR
Definition: typedefs.h:56
#define ERROR_SUCCESS
Definition: deptool.c:10
uint16_t * PWSTR
Definition: typedefs.h:55
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
WORD dmDriverExtra
Definition: wingdi.h:1620
long LONG
Definition: pedump.c:60
smooth NULL
Definition: ftsmooth.c:416
PDEVMODEW DuplicateDevMode(PDEVMODEW pInput)
Definition: tools.c:61
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
_In_z_ PCWSTR pwszValueName
Definition: ntuser.h:36
WORD dmSize
Definition: wingdi.h:1619
#define CopyMemory
Definition: winbase.h:1646
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERR(fmt,...)
Definition: debug.h:109
PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName)
Definition: tools.c:26
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
BYTE * PBYTE
Definition: pedump.c:66