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: base/applications/sndvol32/misc.c
23 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com>
31 LengthOfStrResource(IN HINSTANCE hInst
,
43 /* There are always blocks of 16 strings */
44 lpName
= (LPWSTR
)MAKEINTRESOURCE((uID
>> 4) + 1);
46 /* Find the string table block */
47 if ((hrSrc
= FindResourceW(hInst
,
49 (LPWSTR
)RT_STRING
)) &&
50 (hRes
= LoadResource(hInst
,
52 (lpStr
= LockResource(hRes
)))
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
++)
60 lpStr
+= (*lpStr
) + 1;
63 /* Found the string */
70 AllocAndLoadString(OUT LPWSTR
*lpTarget
,
76 ln
= LengthOfStrResource(hInst
,
80 (*lpTarget
) = (LPWSTR
)LocalAlloc(LMEM_FIXED
,
82 if ((*lpTarget
) != NULL
)
84 INT Ret
= LoadStringW(hInst
,
90 LocalFree((HLOCAL
)(*lpTarget
));
99 LoadAndFormatString(IN HINSTANCE hInstance
,
101 OUT LPWSTR
*lpTarget
,
108 if (AllocAndLoadString(&lpFormat
,
112 va_start(lArgs
, lpTarget
);
113 /* let's use FormatMessage to format it because it has the ability to
114 allocate memory automatically */
115 Ret
= FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
124 LocalFree((HLOCAL
)lpFormat
);
130 static const TCHAR AppRegSettings
[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control");
131 //static const TCHAR AppOptionsKey[] = TEXT("Options");
132 static const TCHAR LineStatesValue
[] = TEXT("LineStates");
133 //static const TCHAR StyleValue[] = TEXT("Style");
135 HKEY hAppSettingsKey
= NULL
;
140 return RegCreateKeyEx(HKEY_CURRENT_USER
,
144 REG_OPTION_NON_VOLATILE
,
145 KEY_READ
| KEY_WRITE
,
148 NULL
) == ERROR_SUCCESS
;
154 if (hAppSettingsKey
!= NULL
)
156 RegCloseKey(hAppSettingsKey
);
157 hAppSettingsKey
= NULL
;
162 WriteLineConfig(IN LPTSTR szDeviceName
,
163 IN LPTSTR szLineName
,
164 IN PSNDVOL_REG_LINESTATE LineState
,
168 TCHAR szDevRegKey
[MAX_PATH
];
171 _stprintf(szDevRegKey
,
176 if (RegCreateKeyEx(hAppSettingsKey
,
180 REG_OPTION_NON_VOLATILE
,
181 KEY_READ
| KEY_WRITE
,
184 NULL
) == ERROR_SUCCESS
)
186 /* now update line states */
187 RegSetValueEx(hLineKey
, LineStatesValue
, 0, REG_BINARY
, (const BYTE
*)LineState
, cbSize
);
190 RegCloseKey(hLineKey
);
197 ReadLineConfig(IN LPTSTR szDeviceName
,
198 IN LPTSTR szLineName
,
199 IN LPTSTR szControlName
,
205 PSNDVOL_REG_LINESTATE LineStates
= NULL
;
206 TCHAR szDevRegKey
[MAX_PATH
];
209 _stprintf(szDevRegKey
,
214 if (RegCreateKeyEx(hAppSettingsKey
,
218 REG_OPTION_NON_VOLATILE
,
219 KEY_READ
| KEY_WRITE
,
222 NULL
) == ERROR_SUCCESS
)
224 if (RegQueryValueEx(hLineKey
,
229 &Size
) != ERROR_SUCCESS
||
230 Type
!= REG_BINARY
||
231 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
236 LineStates
= HeapAlloc(GetProcessHeap(),
240 if (LineStates
!= NULL
)
242 if (RegQueryValueEx(hLineKey
,
247 &Size
) != ERROR_SUCCESS
||
248 Type
!= REG_BINARY
||
249 Size
== 0 || (Size
% sizeof(SNDVOL_REG_LINESTATE
) != 0))
254 /* try to find the control */
255 for (i
= 0; i
< Size
/ sizeof(SNDVOL_REG_LINESTATE
); i
++)
257 if (!_tcscmp(szControlName
,
258 LineStates
[i
].LineName
))
260 *Flags
= LineStates
[i
].Flags
;
268 HeapFree(GetProcessHeap(),
271 RegCloseKey(hLineKey
);