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
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS Sound Volume Control
23 * FILE: subsys/system/sndvol32/misc.c
24 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
30 LengthOfStrResource(IN HINSTANCE hInst
,
42 /* There are always blocks of 16 strings */
43 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
45 /* Find the string table block */
46 if ((hrSrc
= FindResourceW(hInst
,
48 (LPWSTR
)RT_STRING
)) &&
49 (hRes
= LoadResource(hInst
,
51 (lpStr
= LockResource(hRes
)))
55 /* Find the string we're looking for */
56 uID
&= 0xF; /* position in the block, same as % 16 */
57 for (x
= 0; x
< uID
; x
++)
59 lpStr
+= (*lpStr
) + 1;
62 /* Found the string */
69 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
75 ln
= LengthOfStrResource(hInst
,
79 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
81 if ((*lpTarget
) != NULL
)
83 INT Ret
= LoadStringW(hInst
,
89 LocalFree((HLOCAL
)(*lpTarget
));
98 LoadAndFormatString(IN HINSTANCE hInstance
,
100 OUT LPWSTR
*lpTarget
,
107 if (AllocAndLoadString(&lpFormat
,
111 va_start(lArgs
, lpTarget
);
112 /* let's use FormatMessage to format it because it has the ability to
113 allocate memory automatically */
114 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
123 LocalFree((HLOCAL
)lpFormat
);
129 static const TCHAR AppRegSettings
[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control");
130 static const TCHAR AppOptionsKey
[] = TEXT("Options");
131 static const TCHAR LineStatesValue
[] = TEXT("LineStates");
132 static const TCHAR StyleValue
[] = TEXT("Style");
134 HKEY hAppSettingsKey
= NULL
;
139 return RegCreateKeyEx(HKEY_CURRENT_USER
,
143 REG_OPTION_NON_VOLATILE
,
144 KEY_READ
| KEY_WRITE
,
147 NULL
) == ERROR_SUCCESS
;
153 if (hAppSettingsKey
!= NULL
)
155 RegCloseKey(hAppSettingsKey
);
156 hAppSettingsKey
= NULL
;
161 WriteLineConfig(IN LPTSTR szDeviceName
,
162 IN LPTSTR szLineName
,
163 IN PSNDVOL_REG_LINESTATE LineState
,
167 TCHAR szDevRegKey
[MAX_PATH
];
170 _stprintf(szDevRegKey
,
175 if (RegCreateKeyEx(hAppSettingsKey
,
179 REG_OPTION_NON_VOLATILE
,
180 KEY_READ
| KEY_WRITE
,
183 NULL
) == ERROR_SUCCESS
)
185 /* now update line states */
186 RegSetValueEx(hLineKey
, LineStatesValue
, 0, REG_BINARY
, (const BYTE
*)LineState
, cbSize
);
189 RegCloseKey(hLineKey
);
196 ReadLineConfig(IN LPTSTR szDeviceName
,
197 IN LPTSTR szLineName
,
198 IN LPTSTR szControlName
,
204 PSNDVOL_REG_LINESTATE LineStates
= NULL
;
205 TCHAR szDevRegKey
[MAX_PATH
];
208 _stprintf(szDevRegKey
,
213 if (RegCreateKeyEx(hAppSettingsKey
,
217 REG_OPTION_NON_VOLATILE
,
218 KEY_READ
| KEY_WRITE
,
221 NULL
) == ERROR_SUCCESS
)
223 if (RegQueryValueEx(hLineKey
,
228 &Size
) != ERROR_SUCCESS
||
229 Type
!= REG_BINARY
||
230 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
235 LineStates
= HeapAlloc(GetProcessHeap(),
239 if (LineStates
!= NULL
)
241 if (RegQueryValueEx(hLineKey
,
246 &Size
) != ERROR_SUCCESS
||
247 Type
!= REG_BINARY
||
248 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
253 /* try to find the control */
254 for (i
= 0; i
< Size
/ sizeof(SNDVOL_REG_LINESTATE
); i
++)
256 if (!_tcscmp(szControlName
,
257 LineStates
[i
].LineName
))
259 *Flags
= LineStates
[i
].Flags
;
267 HeapFree(GetProcessHeap(),
270 RegCloseKey(hLineKey
);