ReactOS  0.4.12-dev-36-g472787f
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 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)
 

Variables

static const TCHAR AppRegSettings [] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control")
 
static const TCHAR LineStatesValue [] = TEXT("LineStates")
 
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 }
__wchar_t WCHAR
Definition: xmlstorage.h:180
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
#define LMEM_FIXED
Definition: winbase.h:349
HINSTANCE hInst
Definition: dxdiag.c:13
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
static LPWSTR
Definition: misc.c:35
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1373
INT LengthOfStrResource(IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:23

◆ CloseAppConfig()

VOID CloseAppConfig ( VOID  )

Definition at line 152 of file misc.c.

Referenced by _tWinMain().

153 {
154  if (hAppSettingsKey != NULL)
155  {
158  }
159 }
HKEY hAppSettingsKey
Definition: misc.c:135
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416

◆ InitAppConfig()

BOOL InitAppConfig ( VOID  )

Definition at line 138 of file misc.c.

Referenced by _tWinMain().

139 {
142  0,
143  NULL,
146  NULL,
148  NULL) == ERROR_SUCCESS;
149 }
HKEY hAppSettingsKey
Definition: misc.c:135
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define HKEY_CURRENT_USER
Definition: winreg.h:11
static const TCHAR AppRegSettings[]
Definition: misc.c:130
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
#define RegCreateKeyEx
Definition: winreg.h:501

◆ 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 }
#define MAKEINTRESOURCE
Definition: winuser.h:591
_In_ LPCSTR lpName
Definition: winbase.h:2729
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
unsigned int UINT
Definition: ndis.h:50
#define RT_STRING
Definition: pedump.c:368
HINSTANCE hInst
Definition: dxdiag.c:13
INT x
Definition: msvc.h:62
static LPWSTR
Definition: misc.c:35
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ 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 
108  if (AllocAndLoadString(&lpFormat,
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 
124  LocalFree((HLOCAL)lpFormat);
125  }
126 
127  return Ret;
128 }
#define FORMAT_MESSAGE_FROM_STRING
Definition: winbase.h:402
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
HINSTANCE hInstance
Definition: charmap.c:20
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
char * va_list
Definition: acmsvcex.h:78
unsigned long DWORD
Definition: ntddk_ex.h:95
LPCWSTR lpFormat
Definition: trayclock.cpp:32
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
INT AllocAndLoadString(OUT LPWSTR *lpTarget, IN HINSTANCE hInst, IN UINT uID)
Definition: misc.c:50
#define va_start(ap, A)
Definition: acmsvcex.h:91
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ ReadLineConfig()

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

Definition at line 197 of file misc.c.

Referenced by EnumConnectionsCallback(), and PrefDlgAddConnection().

201 {
202  HKEY hLineKey;
203  DWORD Type;
204  DWORD i, Size = 0;
205  PSNDVOL_REG_LINESTATE LineStates = NULL;
206  TCHAR szDevRegKey[MAX_PATH];
207  BOOL Ret = FALSE;
208 
209  _stprintf(szDevRegKey,
210  TEXT("%s\\%s"),
211  szDeviceName,
212  szLineName);
213 
215  szDevRegKey,
216  0,
217  NULL,
220  NULL,
221  &hLineKey,
222  NULL) == ERROR_SUCCESS)
223  {
224  if (RegQueryValueEx(hLineKey,
226  NULL,
227  &Type,
228  NULL,
229  &Size) != ERROR_SUCCESS ||
230  Type != REG_BINARY ||
231  Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0))
232  {
233  goto ExitClose;
234  }
235 
236  LineStates = HeapAlloc(GetProcessHeap(),
238  Size);
239 
240  if (LineStates != NULL)
241  {
242  if (RegQueryValueEx(hLineKey,
244  NULL,
245  &Type,
246  (LPBYTE)LineStates,
247  &Size) != ERROR_SUCCESS ||
248  Type != REG_BINARY ||
249  Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0))
250  {
251  goto ExitClose;
252  }
253 
254  /* try to find the control */
255  for (i = 0; i < Size / sizeof(SNDVOL_REG_LINESTATE); i++)
256  {
257  if (!_tcscmp(szControlName,
258  LineStates[i].LineName))
259  {
260  *Flags = LineStates[i].Flags;
261  Ret = TRUE;
262  break;
263  }
264  }
265  }
266 
267 ExitClose:
269  0,
270  LineStates);
271  RegCloseKey(hLineKey);
272  }
273 
274  return Ret;
275 }
#define RegQueryValueEx
Definition: winreg.h:524
HKEY hAppSettingsKey
Definition: misc.c:135
#define TRUE
Definition: types.h:120
Type
Definition: Type.h:6
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
GLenum GLclampf GLint i
Definition: glfuncs.h:14
struct _SNDVOL_REG_LINESTATE SNDVOL_REG_LINESTATE
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
static const TCHAR LineStatesValue[]
Definition: misc.c:132
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
char TCHAR
Definition: xmlstorage.h:189
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR szDeviceName[]
Definition: provider.c:53
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define _stprintf
Definition: utility.h:124
#define TEXT(s)
Definition: k32.h:26
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define HeapFree(x, y, z)
Definition: compat.h:394
#define RegCreateKeyEx
Definition: winreg.h:501

◆ WriteLineConfig()

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

Definition at line 162 of file misc.c.

Referenced by WriteLineSettings().

166 {
167  HKEY hLineKey;
168  TCHAR szDevRegKey[MAX_PATH];
169  BOOL Ret = FALSE;
170 
171  _stprintf(szDevRegKey,
172  TEXT("%s\\%s"),
173  szDeviceName,
174  szLineName);
175 
177  szDevRegKey,
178  0,
179  NULL,
182  NULL,
183  &hLineKey,
184  NULL) == ERROR_SUCCESS)
185  {
186  /* now update line states */
187  RegSetValueEx(hLineKey, LineStatesValue, 0, REG_BINARY, (const BYTE*)LineState, cbSize);
188  Ret = TRUE;
189 
190  RegCloseKey(hLineKey);
191  }
192 
193  return Ret;
194 }
HKEY hAppSettingsKey
Definition: misc.c:135
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static const TCHAR LineStatesValue[]
Definition: misc.c:132
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
char TCHAR
Definition: xmlstorage.h:189
unsigned int BOOL
Definition: ntddk_ex.h:94
#define MAX_PATH
Definition: compat.h:26
static const WCHAR szDeviceName[]
Definition: provider.c:53
unsigned char BYTE
Definition: ntddk_ex.h:96
#define _stprintf
Definition: utility.h:124
#define TEXT(s)
Definition: k32.h:26
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501

Variable Documentation

◆ AppRegSettings

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

Definition at line 130 of file misc.c.

Referenced by InitAppConfig().

◆ hAppSettingsKey

HKEY hAppSettingsKey = NULL

Definition at line 135 of file misc.c.

◆ LineStatesValue

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

Definition at line 132 of file misc.c.

Referenced by ReadLineConfig(), and WriteLineConfig().