ReactOS 0.4.16-dev-106-g10b08aa
tools.c File Reference
#include "precomp.h"
Include dependency graph for tools.c:

Go to the source code of this file.

Functions

AllocAndRegQueryWSZ

Queries a REG_SZ value in the registry, allocates memory for it and returns a buffer containing the value. You have to free this buffer using DllFreeSplMem.

Parameters
hKeyHKEY variable of the key opened with RegOpenKeyExW.
pwszValueNameName of the REG_SZ value to query.
Returns
Pointer to the buffer containing the value or NULL in case of failure.
PWSTR AllocAndRegQueryWSZ (HKEY hKey, PCWSTR pwszValueName)
 
PDEVMODEW DuplicateDevMode (PDEVMODEW pInput)
 
LONG copy_servername_from_name (LPCWSTR name, LPWSTR target)
 

Function Documentation

◆ AllocAndRegQueryWSZ()

PWSTR AllocAndRegQueryWSZ ( HKEY  hKey,
PCWSTR  pwszValueName 
)

Definition at line 26 of file tools.c.

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}
#define ERR(fmt,...)
Definition: precomp.h:57
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
uint16_t * PWSTR
Definition: typedefs.h:56
_In_z_ PCWSTR pwszValueName
Definition: ntuser.h:42
BOOL WINAPI DllFreeSplMem(PVOID pMem)
Definition: memory.c:112
PVOID WINAPI DllAllocSplMem(DWORD dwBytes)
Definition: memory.c:95

Referenced by InitializePrinterList(), and InitializePrintMonitorList().

◆ copy_servername_from_name()

LONG copy_servername_from_name ( LPCWSTR  name,
LPWSTR  target 
)

Definition at line 89 of file tools.c.

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 -(LONG)serverlen;
113
114 if (target)
115 {
116 memcpy(target, server, serverlen * sizeof(WCHAR));
117 target[serverlen] = '\0';
118 }
119
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}
#define FIXME(fmt,...)
Definition: precomp.h:53
BOOL WINAPI GetComputerNameW(LPWSTR lpBuffer, LPDWORD lpnSize)
Definition: compname.c:446
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define wcschr
Definition: compat.h:17
#define lstrlenW
Definition: compat.h:750
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
GLenum target
Definition: glext.h:7315
#define debugstr_wn
Definition: kernel32.h:33
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static PVOID ptr
Definition: dispmode.c:27
_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)
Definition: name.c:39
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by LocalAddMonitor(), LocalAddPort(), LocalAddPortEx(), LocalAddPrinterDriver(), LocalAddPrinterDriverEx(), LocalConfigurePort(), LocalDeleteMonitor(), LocalDeletePort(), and LocalSetPort().

◆ DuplicateDevMode()

PDEVMODEW DuplicateDevMode ( PDEVMODEW  pInput)

Definition at line 61 of file tools.c.

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}
WORD dmDriverExtra
Definition: wingdi.h:1621
WORD dmSize
Definition: wingdi.h:1620
#define CopyMemory
Definition: winbase.h:1710

Referenced by _LocalOpenPrinterHandle(), CreateJob(), and ReadJobShadowFile().