ReactOS 0.4.15-dev-8235-gcd88a97
misc.c File Reference
#include "sndvol32.h"
#include <winreg.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

static INT LengthOfStrResource (IN HINSTANCE hInst, IN UINT uID)
 
INT AllocAndLoadString (OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
 
DWORD LoadAndFormatString (IN HINSTANCE hInstance, IN UINT uID, OUT LPWSTR *lpTarget,...)
 
BOOL InitAppConfig (VOID)
 
VOID CloseAppConfig (VOID)
 
BOOL LoadXYCoordWnd (IN PPREFERENCES_CONTEXT PrefContext)
 
BOOL SaveXYCoordWnd (IN HWND hWnd, IN PPREFERENCES_CONTEXT PrefContext)
 
BOOL WriteLineConfig (IN LPTSTR szDeviceName, IN LPTSTR szLineName, IN PSNDVOL_REG_LINESTATE LineState, IN DWORD cbSize)
 
BOOL ReadLineConfig (IN LPTSTR szDeviceName, IN LPTSTR szLineName, IN LPTSTR szControlName, OUT DWORD *Flags)
 
DWORD GetStyleValue (VOID)
 

Variables

static const TCHAR AppRegSettings [] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control")
 
static const TCHAR AppOptionsKey [] = TEXT("Options")
 
static const TCHAR LineStatesValue [] = TEXT("LineStates")
 
static const TCHAR StyleValue [] = TEXT("Style")
 
HKEY hAppSettingsKey = NULL
 

Function Documentation

◆ AllocAndLoadString()

INT AllocAndLoadString ( OUT LPWSTR lpTarget,
IN HINSTANCE  hInst,
IN UINT  uID 
)

Definition at line 70 of file misc.c.

73{
74 INT ln;
75
77 uID);
78 if (ln++ > 0)
79 {
80 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED,
81 ln * sizeof(WCHAR));
82 if ((*lpTarget) != NULL)
83 {
84 INT Ret = LoadStringW(hInst,
85 uID,
86 *lpTarget,
87 ln);
88 if (!Ret)
89 {
90 LocalFree((HLOCAL)(*lpTarget));
91 }
92 return Ret;
93 }
94 }
95 return 0;
96}
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23
#define NULL
Definition: types.h:112
HINSTANCE hInst
Definition: dxdiag.c:13
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
int32_t INT
Definition: typedefs.h:58
#define LMEM_FIXED
Definition: winbase.h:368
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ CloseAppConfig()

VOID CloseAppConfig ( VOID  )

Definition at line 152 of file misc.c.

153{
154 if (hAppSettingsKey != NULL)
155 {
158 }
159}
HKEY hAppSettingsKey
Definition: misc.c:135
#define RegCloseKey(hKey)
Definition: registry.h:49

Referenced by _tWinMain().

◆ GetStyleValue()

DWORD GetStyleValue ( VOID  )

Definition at line 388 of file misc.c.

389{
390 HKEY hOptionsKey;
391 DWORD dwStyle = 0, dwSize;
392
395 0,
396 KEY_READ,
397 &hOptionsKey) == ERROR_SUCCESS)
398 {
399 dwSize = sizeof(DWORD);
400 RegQueryValueEx(hOptionsKey,
402 NULL,
403 NULL,
404 (LPBYTE)&dwStyle,
405 &dwSize);
406
407 RegCloseKey(hOptionsKey);
408 }
409
410 return dwStyle;
411}
static const TCHAR StyleValue[]
Definition: misc.c:133
static const TCHAR AppOptionsKey[]
Definition: misc.c:131
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define KEY_READ
Definition: nt_native.h:1023
#define DWORD
Definition: nt_native.h:44
unsigned char * LPBYTE
Definition: typedefs.h:53
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524

Referenced by _tWinMain().

◆ InitAppConfig()

BOOL InitAppConfig ( VOID  )

Definition at line 138 of file misc.c.

139{
142 0,
143 NULL,
146 NULL,
149}
static const TCHAR AppRegSettings[]
Definition: misc.c:130
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegCreateKeyEx
Definition: winreg.h:501

Referenced by _tWinMain().

◆ LengthOfStrResource()

static INT LengthOfStrResource ( IN HINSTANCE  hInst,
IN UINT  uID 
)
static

Definition at line 31 of file misc.c.

33{
34 HRSRC hrSrc;
35 HGLOBAL hRes;
36 LPWSTR lpName, lpStr;
37
38 if (hInst == NULL)
39 {
40 return -1;
41 }
42
43 /* There are always blocks of 16 strings */
44 lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1);
45
46 /* Find the string table block */
47 if ((hrSrc = FindResourceW(hInst,
48 lpName,
49 (LPWSTR)RT_STRING)) &&
50 (hRes = LoadResource(hInst,
51 hrSrc)) &&
52 (lpStr = LockResource(hRes)))
53 {
54 UINT x;
55
56 /* Find the string we're looking for */
57 uID &= 0xF; /* position in the block, same as % 16 */
58 for (x = 0; x < uID; x++)
59 {
60 lpStr += (*lpStr) + 1;
61 }
62
63 /* Found the string */
64 return (int)(*lpStr);
65 }
66 return -1;
67}
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
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
_In_ LPCSTR lpName
Definition: winbase.h:2789
#define MAKEINTRESOURCE
Definition: winuser.h:591

◆ LoadAndFormatString()

DWORD LoadAndFormatString ( IN HINSTANCE  hInstance,
IN UINT  uID,
OUT LPWSTR lpTarget,
  ... 
)

Definition at line 99 of file misc.c.

103{
104 DWORD Ret = 0;
106 va_list lArgs;
107
109 hInstance,
110 uID) > 0)
111 {
112 va_start(lArgs, lpTarget);
113 /* let's use FormatMessage to format it because it has the ability to
114 allocate memory automatically */
116 lpFormat,
117 0,
118 0,
119 (LPWSTR)lpTarget,
120 0,
121 &lArgs);
122 va_end(lArgs);
123
125 }
126
127 return Ret;
128}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
INT AllocAndLoadString(OUT LPTSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:59
HINSTANCE hInstance
Definition: charmap.c:19
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
LPCWSTR lpFormat
Definition: trayclock.cpp:32
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:421
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419

◆ LoadXYCoordWnd()

BOOL LoadXYCoordWnd ( IN PPREFERENCES_CONTEXT  PrefContext)

Definition at line 162 of file misc.c.

163{
164 HKEY hKey;
165 LONG lResult;
166 TCHAR DeviceMixerSettings[256];
168 DWORD cbData = sizeof(dwData);
169
170 /* Append the registry key path and device name key into one single string */
171 StringCchPrintf(DeviceMixerSettings, _countof(DeviceMixerSettings), TEXT("%s\\%s"), AppRegSettings, PrefContext->DeviceName);
172
174 DeviceMixerSettings,
175 0,
176 KEY_READ,
177 &hKey);
178 if (lResult != ERROR_SUCCESS)
179 {
180 return FALSE;
181 }
182
183 lResult = RegQueryValueEx(hKey,
184 TEXT("X"),
185 0,
186 0,
187 (LPBYTE)&dwData,
188 &cbData);
189 if (lResult != ERROR_SUCCESS)
190 {
192 return FALSE;
193 }
194
195 /* Cache the X coordinate point */
196 PrefContext->MixerWindow->WndPosX = dwData;
197
198 lResult = RegQueryValueEx(hKey,
199 TEXT("Y"),
200 0,
201 0,
202 (LPBYTE)&dwData,
203 &cbData);
204 if (lResult != ERROR_SUCCESS)
205 {
207 return FALSE;
208 }
209
210 /* Cache the Y coordinate point */
211 PrefContext->MixerWindow->WndPosY = dwData;
212
214 return TRUE;
215}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
FxAutoRegKey hKey
#define TEXT(s)
Definition: k32.h:26
static HANDLE ULONG_PTR dwData
Definition: file.c:35
long LONG
Definition: pedump.c:60
#define _countof(array)
Definition: sndvol32.h:70
#define StringCchPrintf
Definition: strsafe.h:517
char TCHAR
Definition: xmlstorage.h:189

Referenced by MainWindowProc().

◆ ReadLineConfig()

BOOL ReadLineConfig ( IN LPTSTR  szDeviceName,
IN LPTSTR  szLineName,
IN LPTSTR  szControlName,
OUT DWORD Flags 
)

Definition at line 307 of file misc.c.

311{
312 HKEY hLineKey;
313 DWORD Type;
314 DWORD i, Size = 0;
315 PSNDVOL_REG_LINESTATE LineStates = NULL;
316 TCHAR szDevRegKey[MAX_PATH];
317 BOOL Ret = FALSE;
318
319 _stprintf(szDevRegKey,
320 TEXT("%s\\%s"),
322 szLineName);
323
325 szDevRegKey,
326 0,
327 NULL,
330 NULL,
331 &hLineKey,
333 {
334 if (RegQueryValueEx(hLineKey,
336 NULL,
337 &Type,
338 NULL,
339 &Size) != ERROR_SUCCESS ||
340 Type != REG_BINARY ||
341 Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0))
342 {
343 goto ExitClose;
344 }
345
346 LineStates = HeapAlloc(GetProcessHeap(),
348 Size);
349
350 if (LineStates != NULL)
351 {
352 if (RegQueryValueEx(hLineKey,
354 NULL,
355 &Type,
356 (LPBYTE)LineStates,
357 &Size) != ERROR_SUCCESS ||
358 Type != REG_BINARY ||
359 Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0))
360 {
361 goto ExitClose;
362 }
363
364 /* try to find the control */
365 for (i = 0; i < Size / sizeof(SNDVOL_REG_LINESTATE); i++)
366 {
367 if (!_tcscmp(szControlName,
368 LineStates[i].LineName))
369 {
370 *Flags = LineStates[i].Flags;
371 Ret = TRUE;
372 break;
373 }
374 }
375 }
376
377ExitClose:
379 0,
380 LineStates);
381 RegCloseKey(hLineKey);
382 }
383
384 return Ret;
385}
Type
Definition: Type.h:7
static const TCHAR LineStatesValue[]
Definition: misc.c:132
static const WCHAR szDeviceName[]
Definition: provider.c:56
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tcscmp
Definition: tchar.h:1424
#define _stprintf
Definition: utility.h:124
#define REG_BINARY
Definition: nt_native.h:1496
struct _SNDVOL_REG_LINESTATE SNDVOL_REG_LINESTATE
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170

Referenced by EnumConnectionsCallback(), and PrefDlgAddConnection().

◆ SaveXYCoordWnd()

BOOL SaveXYCoordWnd ( IN HWND  hWnd,
IN PPREFERENCES_CONTEXT  PrefContext 
)

Definition at line 218 of file misc.c.

220{
221 HKEY hKey;
222 LONG lResult;
223 TCHAR DeviceMixerSettings[256];
225
226 /* Get the placement coordinate data from the window */
227 wp.length = sizeof(WINDOWPLACEMENT);
229
230 /* Append the registry key path and device name key into one single string */
231 StringCchPrintf(DeviceMixerSettings, _countof(DeviceMixerSettings), TEXT("%s\\%s"), AppRegSettings, PrefContext->DeviceName);
232
234 DeviceMixerSettings,
235 0,
237 &hKey);
238 if (lResult != ERROR_SUCCESS)
239 {
240 return FALSE;
241 }
242
243 lResult = RegSetValueEx(hKey,
244 TEXT("X"),
245 0,
246 REG_DWORD,
248 sizeof(wp.rcNormalPosition.left));
249 if (lResult != ERROR_SUCCESS)
250 {
252 return FALSE;
253 }
254
255 lResult = RegSetValueEx(hKey,
256 TEXT("Y"),
257 0,
258 REG_DWORD,
260 sizeof(wp.rcNormalPosition.top));
261 if (lResult != ERROR_SUCCESS)
262 {
264 return FALSE;
265 }
266
268 return TRUE;
269}
HWND hWnd
Definition: settings.c:17
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define REG_DWORD
Definition: sdbapi.c:596
RECT rcNormalPosition
Definition: winuser.h:3295
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
#define RegSetValueEx
Definition: winreg.h:533
BOOL WINAPI GetWindowPlacement(_In_ HWND, _Inout_ WINDOWPLACEMENT *)
struct _WINDOWPLACEMENT WINDOWPLACEMENT

Referenced by MainWindowProc().

◆ WriteLineConfig()

BOOL WriteLineConfig ( IN LPTSTR  szDeviceName,
IN LPTSTR  szLineName,
IN PSNDVOL_REG_LINESTATE  LineState,
IN DWORD  cbSize 
)

Definition at line 272 of file misc.c.

276{
277 HKEY hLineKey;
278 TCHAR szDevRegKey[MAX_PATH];
279 BOOL Ret = FALSE;
280
281 _stprintf(szDevRegKey,
282 TEXT("%s\\%s"),
284 szLineName);
285
287 szDevRegKey,
288 0,
289 NULL,
292 NULL,
293 &hLineKey,
295 {
296 /* now update line states */
297 RegSetValueEx(hLineKey, LineStatesValue, 0, REG_BINARY, (const BYTE*)LineState, cbSize);
298 Ret = TRUE;
299
300 RegCloseKey(hLineKey);
301 }
302
303 return Ret;
304}
unsigned char BYTE
Definition: xxhash.c:193

Referenced by WriteLineSettings().

Variable Documentation

◆ AppOptionsKey

const TCHAR AppOptionsKey[] = TEXT("Options")
static

Definition at line 131 of file misc.c.

Referenced by GetStyleValue().

◆ AppRegSettings

const TCHAR AppRegSettings[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control")
static

Definition at line 130 of file misc.c.

Referenced by InitAppConfig(), LoadXYCoordWnd(), and SaveXYCoordWnd().

◆ hAppSettingsKey

HKEY hAppSettingsKey = NULL

Definition at line 135 of file misc.c.

Referenced by CloseAppConfig(), GetStyleValue(), InitAppConfig(), ReadLineConfig(), and WriteLineConfig().

◆ LineStatesValue

const TCHAR LineStatesValue[] = TEXT("LineStates")
static

Definition at line 132 of file misc.c.

Referenced by ReadLineConfig(), and WriteLineConfig().

◆ StyleValue

const TCHAR StyleValue[] = TEXT("Style")
static

Definition at line 133 of file misc.c.

Referenced by GetStyleValue().