2 * ReactOS Sound Volume Control
3 * Copyright (C) 2004-2005 Thomas Weidenmueller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS Sound Volume Control
22 * FILE: subsys/system/sndvol32/misc.c
23 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
29 LengthOfStrResource(IN HINSTANCE hInst
,
41 /* There are always blocks of 16 strings */
42 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
44 /* Find the string table block */
45 if ((hrSrc
= FindResourceW(hInst
,
47 (LPWSTR
)RT_STRING
)) &&
48 (hRes
= LoadResource(hInst
,
50 (lpStr
= LockResource(hRes
)))
54 /* Find the string we're looking for */
55 uID
&= 0xF; /* position in the block, same as % 16 */
56 for (x
= 0; x
< uID
; x
++)
58 lpStr
+= (*lpStr
) + 1;
61 /* Found the string */
68 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
74 ln
= LengthOfStrResource(hInst
,
78 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
80 if ((*lpTarget
) != NULL
)
82 INT Ret
= LoadStringW(hInst
,
88 LocalFree((HLOCAL
)(*lpTarget
));
97 LoadAndFormatString(IN HINSTANCE hInstance
,
106 if (AllocAndLoadString(&lpFormat
,
110 va_start(lArgs
, lpTarget
);
111 /* let's use FormatMessage to format it because it has the ability to
112 allocate memory automatically */
113 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
122 LocalFree((HLOCAL
)lpFormat
);
128 static const TCHAR AppRegSettings
[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control");
129 static const TCHAR AppOptionsKey
[] = TEXT("Options");
130 static const TCHAR LineStatesValue
[] = TEXT("LineStates");
131 static const TCHAR StyleValue
[] = TEXT("Style");
133 HKEY hAppSettingsKey
= NULL
;
138 return RegCreateKeyEx(HKEY_CURRENT_USER
,
142 REG_OPTION_NON_VOLATILE
,
143 KEY_READ
| KEY_WRITE
,
146 NULL
) == ERROR_SUCCESS
;
152 if (hAppSettingsKey
!= NULL
)
154 RegCloseKey(hAppSettingsKey
);
155 hAppSettingsKey
= NULL
;
160 WriteLineConfig(IN LPTSTR szDeviceName
,
161 IN LPTSTR szLineName
,
162 IN PSNDVOL_REG_LINESTATE LineState
,
166 TCHAR szDevRegKey
[MAX_PATH
];
169 _stprintf(szDevRegKey
,
174 if (RegCreateKeyEx(hAppSettingsKey
,
178 REG_OPTION_NON_VOLATILE
,
179 KEY_READ
| KEY_WRITE
,
182 NULL
) == ERROR_SUCCESS
)
184 /* now update line states */
185 RegSetValueEx(hLineKey
, LineStatesValue
, 0, REG_BINARY
, (const BYTE
*)LineState
, cbSize
);
188 RegCloseKey(hLineKey
);
195 ReadLineConfig(IN LPTSTR szDeviceName
,
196 IN LPTSTR szLineName
,
197 IN LPTSTR szControlName
,
203 PSNDVOL_REG_LINESTATE LineStates
= NULL
;
204 TCHAR szDevRegKey
[MAX_PATH
];
207 _stprintf(szDevRegKey
,
212 if (RegCreateKeyEx(hAppSettingsKey
,
216 REG_OPTION_NON_VOLATILE
,
217 KEY_READ
| KEY_WRITE
,
220 NULL
) == ERROR_SUCCESS
)
222 if (RegQueryValueEx(hLineKey
,
227 &Size
) != ERROR_SUCCESS
||
228 Type
!= REG_BINARY
||
229 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
234 LineStates
= HeapAlloc(GetProcessHeap(),
238 if (LineStates
!= NULL
)
240 if (RegQueryValueEx(hLineKey
,
245 &Size
) != ERROR_SUCCESS
||
246 Type
!= REG_BINARY
||
247 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
252 /* try to find the control */
253 for (i
= 0; i
< Size
/ sizeof(SNDVOL_REG_LINESTATE
); i
++)
255 if (!_tcscmp(szControlName
,
256 LineStates
[i
].LineName
))
258 *Flags
= LineStates
[i
].Flags
;
266 HeapFree(GetProcessHeap(),
269 RegCloseKey(hLineKey
);