ReactOS 0.4.15-dev-7704-gc07eb9f
vista.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winuser.h>
#include <ndk/rtlfuncs.h>
#include <wine/debug.h>
#include <wine/unicode.h>
Include dependency graph for vista.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define NTOS_MODE_USER
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (shell)
 
static int load_string (HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
 
LONG WINAPI RegLoadMUIStringW (IN HKEY hKey, IN LPCWSTR pszValue OPTIONAL, OUT LPWSTR pszOutBuf, IN DWORD cbOutBuf, OUT LPDWORD pcbData OPTIONAL, IN DWORD Flags, IN LPCWSTR pszDirectory OPTIONAL)
 
LONG WINAPI RegLoadMUIStringA (IN HKEY hKey, IN LPCSTR pszValue OPTIONAL, OUT LPSTR pszOutBuf, IN DWORD cbOutBuf, OUT LPDWORD pcbData OPTIONAL, IN DWORD Flags, IN LPCSTR pszDirectory OPTIONAL)
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 17 of file vista.c.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 18 of file vista.c.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 24 of file vista.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 16 of file vista.c.

Function Documentation

◆ load_string()

static int load_string ( HINSTANCE  hModule,
UINT  resId,
LPWSTR  pwszBuffer,
INT  cMaxChars 
)
static

Definition at line 39 of file vista.c.

40{
42 HRSRC hResource;
44 int idxString;
45
46 /* Negative values have to be inverted. */
47 if (HIWORD(resId) == 0xffff)
48 resId = (UINT)(-((INT)resId));
49
50 /* Load the resource into memory and get a pointer to it. */
51 hResource = FindResourceW(hModule, MAKEINTRESOURCEW(LOWORD(resId >> 4) + 1), (LPWSTR)RT_STRING);
52 if (!hResource) return 0;
53 hMemory = LoadResource(hModule, hResource);
54 if (!hMemory) return 0;
56
57 /* Strings are length-prefixed. Lowest nibble of resId is an index. */
58 idxString = resId & 0xf;
59 while (idxString--) pString += *pString + 1;
60
61 /* If no buffer is given, return length of the string. */
62 if (!pwszBuffer) return *pString;
63
64 /* Else copy over the string, respecting the buffer size. */
65 cMaxChars = (*pString < cMaxChars) ? *pString : (cMaxChars - 1);
66 if (cMaxChars >= 0)
67 {
68 memcpy(pwszBuffer, pString+1, cMaxChars * sizeof(WCHAR));
69 pwszBuffer[cMaxChars] = L'\0';
70 }
71
72 return cMaxChars;
73}
HMODULE hModule
Definition: animate.c:44
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
FxString * pString
WDFMEMORY hMemory
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
#define RT_STRING
Definition: pedump.c:368
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by RegLoadMUIStringW().

◆ RegLoadMUIStringA()

LONG WINAPI RegLoadMUIStringA ( IN HKEY  hKey,
IN LPCSTR pszValue  OPTIONAL,
OUT LPSTR  pszOutBuf,
IN DWORD  cbOutBuf,
OUT LPDWORD pcbData  OPTIONAL,
IN DWORD  Flags,
IN LPCSTR pszDirectory  OPTIONAL 
)

Definition at line 180 of file vista.c.

187{
188 UNICODE_STRING valueW, baseDirW;
189 WCHAR *pwszBuffer;
190 DWORD cbData = cbOutBuf * sizeof(WCHAR);
191 LONG result;
192
193 valueW.Buffer = baseDirW.Buffer = pwszBuffer = NULL;
194 if (!RtlCreateUnicodeStringFromAsciiz(&valueW, pszValue) ||
195 !RtlCreateUnicodeStringFromAsciiz(&baseDirW, pszDirectory) ||
196 !(pwszBuffer = HeapAlloc(GetProcessHeap(), 0, cbData)))
197 {
199 goto cleanup;
200 }
201
202 result = RegLoadMUIStringW(hKey, valueW.Buffer, pwszBuffer, cbData, NULL, Flags,
203 baseDirW.Buffer);
204
205 if (result == ERROR_SUCCESS)
206 {
207 cbData = WideCharToMultiByte(CP_ACP, 0, pwszBuffer, -1, pszOutBuf, cbOutBuf, NULL, NULL);
208 if (pcbData)
209 *pcbData = cbData;
210 }
211
212cleanup:
213 HeapFree(GetProcessHeap(), 0, pwszBuffer);
214 RtlFreeUnicodeString(&baseDirW);
216
217 return result;
218}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define WideCharToMultiByte
Definition: compat.h:111
static void cleanup(void)
Definition: main.c:1335
static const WCHAR valueW[]
Definition: object.c:48
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
GLuint64EXT * result
Definition: glext.h:11304
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeStringFromAsciiz(_Out_ PUNICODE_STRING Destination, _In_ PCSZ Source)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
long LONG
Definition: pedump.c:60
LONG WINAPI RegLoadMUIStringW(IN HKEY hKey, IN LPCWSTR pszValue OPTIONAL, OUT LPWSTR pszOutBuf, IN DWORD cbOutBuf, OUT LPDWORD pcbData OPTIONAL, IN DWORD Flags, IN LPCWSTR pszDirectory OPTIONAL)
Definition: vista.c:81
_In_ DWORD _Out_writes_bytes_to_opt_ pcbData void _Inout_ DWORD * pcbData
Definition: wincrypt.h:4950
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

◆ RegLoadMUIStringW()

LONG WINAPI RegLoadMUIStringW ( IN HKEY  hKey,
IN LPCWSTR pszValue  OPTIONAL,
OUT LPWSTR  pszOutBuf,
IN DWORD  cbOutBuf,
OUT LPDWORD pcbData  OPTIONAL,
IN DWORD  Flags,
IN LPCWSTR pszDirectory  OPTIONAL 
)

Definition at line 81 of file vista.c.

88{
89 DWORD dwValueType, cbData;
90 LPWSTR pwszTempBuffer = NULL, pwszExpandedBuffer = NULL;
92
93 /* Parameter sanity checks. */
94 if (!hKey || !pszOutBuf)
96
97 if (pszDirectory && *pszDirectory)
98 {
99 FIXME("BaseDir parameter not yet supported!\n");
101 }
102
103 /* Check for value existence and correctness of it's type, allocate a buffer and load it. */
104 result = RegQueryValueExW(hKey, pszValue, NULL, &dwValueType, NULL, &cbData);
105 if (result != ERROR_SUCCESS) goto cleanup;
106 if (!(dwValueType == REG_SZ || dwValueType == REG_EXPAND_SZ) || !cbData)
107 {
109 goto cleanup;
110 }
111 pwszTempBuffer = HeapAlloc(GetProcessHeap(), 0, cbData);
112 if (!pwszTempBuffer)
113 {
115 goto cleanup;
116 }
117 result = RegQueryValueExW(hKey, pszValue, NULL, &dwValueType, (LPBYTE)pwszTempBuffer, &cbData);
118 if (result != ERROR_SUCCESS) goto cleanup;
119
120 /* Expand environment variables, if appropriate, or copy the original string over. */
121 if (dwValueType == REG_EXPAND_SZ)
122 {
123 cbData = ExpandEnvironmentStringsW(pwszTempBuffer, NULL, 0) * sizeof(WCHAR);
124 if (!cbData) goto cleanup;
125 pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData);
126 if (!pwszExpandedBuffer)
127 {
129 goto cleanup;
130 }
131 ExpandEnvironmentStringsW(pwszTempBuffer, pwszExpandedBuffer, cbData);
132 }
133 else
134 {
135 pwszExpandedBuffer = HeapAlloc(GetProcessHeap(), 0, cbData);
136 memcpy(pwszExpandedBuffer, pwszTempBuffer, cbData);
137 }
138
139 /* If the value references a resource based string, parse the value and load the string.
140 * Else just copy over the original value. */
142 if (*pwszExpandedBuffer != L'@') /* '@' is the prefix for resource based string entries. */
143 {
144 lstrcpynW(pszOutBuf, pwszExpandedBuffer, cbOutBuf / sizeof(WCHAR));
145 }
146 else
147 {
148 WCHAR *pComma = wcsrchr(pwszExpandedBuffer, L',');
149 UINT uiStringId;
151
152 /* Format of the expanded value is 'path_to_dll,-resId' */
153 if (!pComma || pComma[1] != L'-')
154 {
156 goto cleanup;
157 }
158
159 uiStringId = _wtoi(pComma+2);
160 *pComma = L'\0';
161
162 hModule = LoadLibraryExW(pwszExpandedBuffer + 1, NULL, LOAD_LIBRARY_AS_DATAFILE);
163 if (!hModule || !load_string(hModule, uiStringId, pszOutBuf, cbOutBuf / sizeof(WCHAR)))
166 }
167
168cleanup:
169 HeapFree(GetProcessHeap(), 0, pwszTempBuffer);
170 HeapFree(GetProcessHeap(), 0, pwszExpandedBuffer);
171 return result;
172}
#define FIXME(fmt,...)
Definition: debug.h:111
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4132
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define wcsrchr
Definition: compat.h:16
#define FreeLibrary(x)
Definition: compat.h:748
#define lstrcpynW
Definition: compat.h:738
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
Definition: loader.c:288
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define REG_SZ
Definition: layer.c:22
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: vista.c:39
unsigned char * LPBYTE
Definition: typedefs.h:53
#define LOAD_LIBRARY_AS_DATAFILE
Definition: winbase.h:342
#define ERROR_BADKEY
Definition: winerror.h:589

Referenced by CDefaultContextMenu::AddStaticContextMenusToMenu(), FileTypesDlg_InsertToLV(), HCR_GetClassNameW(), HCR_MapTypeToValueW(), LoadClassicColorSchemes(), LoadSchemeSizes(), and RegLoadMUIStringA().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( shell  )