ReactOS  0.4.15-dev-1171-gab82533
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 }
78 
79 /******************************************************************
80  * copy_servername_from_name (internal)
81  *
82  * for an external server, the serverpart from the name is copied.
83  *
84  * RETURNS
85  * the length (in WCHAR) of the serverpart (0 for the local computer)
86  * (-length), when the name is too long
87  *
88  */
90 {
92  LPWSTR ptr;
94  DWORD len;
95  DWORD serverlen;
96 
97  if (target) *target = '\0';
98 
99  if (name == NULL) return 0;
100  if ((name[0] != '\\') || (name[1] != '\\')) return 0;
101 
102  server = &name[2];
103  /* skip over both backslash, find separator '\' */
104  ptr = wcschr(server, '\\');
105  serverlen = (ptr) ? ptr - server : lstrlenW(server);
106 
107  /* servername is empty */
108  if (serverlen == 0) return 0;
109 
110  FIXME("found %s\n", debugstr_wn(server, serverlen));
111 
112  if (serverlen > MAX_COMPUTERNAME_LENGTH) return -serverlen;
113 
114  if (target)
115  {
116  memcpy(target, server, serverlen * sizeof(WCHAR));
117  target[serverlen] = '\0';
118  }
119 
120  len = ARRAYSIZE(buffer);
121  if (GetComputerNameW(buffer, &len))
122  {
123  if ((serverlen == len) && (_wcsnicmp(server, buffer, len) == 0))
124  {
125  /* The requested Servername is our computername */
126  return 0;
127  }
128  }
129  return serverlen;
130 }
const uint16_t * PCWSTR
Definition: typedefs.h:57
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
uint16_t * PWSTR
Definition: typedefs.h:56
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
WORD dmDriverExtra
Definition: wingdi.h:1620
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
GLuint buffer
Definition: glext.h:5915
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define lstrlenW
Definition: compat.h:498
LONG copy_servername_from_name(LPCWSTR name, LPWSTR target)
Definition: tools.c:89
long LONG
Definition: pedump.c:60
#define FIXME(fmt,...)
Definition: debug.h:111
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
_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 memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
#define debugstr_wn
Definition: kernel32.h:33
#define ERR(fmt,...)
Definition: debug.h:110
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
PWSTR AllocAndRegQueryWSZ(HKEY hKey, PCWSTR pwszValueName)
Definition: tools.c:26
Definition: name.c:38
GLenum target
Definition: glext.h:7315
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BYTE * PBYTE
Definition: pedump.c:66