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>
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 /* NOTE: do NOT modify SNDVOL_REG_LINESTATE for binary compatibility with XP! */
129 typedef struct _SNDVOL_REG_LINESTATE
132 WCHAR LineName
[MIXER_LONG_NAME_CHARS
];
133 } SNDVOL_REG_LINESTATE
, *PSNDVOL_REG_LINESTATE
;
135 static const TCHAR AppRegSettings
[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control");
136 static const TCHAR AppOptionsKey
[] = TEXT("Options");
137 static const TCHAR LineStatesValue
[] = TEXT("LineStates");
138 static const TCHAR StyleValue
[] = TEXT("Style");
140 HKEY hAppSettingsKey
= NULL
;
145 return RegCreateKeyEx(HKEY_CURRENT_USER
,
149 REG_OPTION_NON_VOLATILE
,
150 KEY_READ
| KEY_WRITE
,
153 NULL
) == ERROR_SUCCESS
;
159 if (hAppSettingsKey
!= NULL
)
161 RegCloseKey(hAppSettingsKey
);
162 hAppSettingsKey
= NULL
;
167 ReadLineConfig(IN LPTSTR szDeviceName
,
168 IN LPTSTR szLineName
,
169 IN LPTSTR szControlName
,
175 PSNDVOL_REG_LINESTATE LineStates
= NULL
;
176 TCHAR szDevRegKey
[MAX_PATH
];
179 _stprintf(szDevRegKey
,
184 if (RegCreateKeyEx(hAppSettingsKey
,
188 REG_OPTION_NON_VOLATILE
,
189 KEY_READ
| KEY_WRITE
,
192 NULL
) == ERROR_SUCCESS
)
194 if (RegQueryValueEx(hLineKey
,
199 &Size
) != ERROR_SUCCESS
||
200 Type
!= REG_BINARY
||
201 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
206 LineStates
= HeapAlloc(GetProcessHeap(),
210 if (LineStates
!= NULL
)
212 if (RegQueryValueEx(hLineKey
,
217 &Size
) != ERROR_SUCCESS
||
218 Type
!= REG_BINARY
||
219 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
224 /* try to find the control */
225 for (i
= 0; i
< Size
/ sizeof(SNDVOL_REG_LINESTATE
); i
++)
227 if (!_tcscmp(szControlName
,
228 LineStates
[i
].LineName
))
230 *Flags
= LineStates
[i
].Flags
;
238 HeapFree(GetProcessHeap(),
241 RegCloseKey(hLineKey
);