Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmisc.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS Sound Volume Control 00003 * Copyright (C) 2004-2005 Thomas Weidenmueller 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 /* $Id: misc.c 51286 2011-04-08 22:04:41Z janderwald $ 00020 * 00021 * COPYRIGHT: See COPYING in the top level directory 00022 * PROJECT: ReactOS Sound Volume Control 00023 * FILE: subsys/system/sndvol32/misc.c 00024 * PROGRAMMERS: Thomas Weidenmueller <w3seek@reactos.com> 00025 */ 00026 #include "sndvol32.h" 00027 00028 00029 static INT 00030 LengthOfStrResource(IN HINSTANCE hInst, 00031 IN UINT uID) 00032 { 00033 HRSRC hrSrc; 00034 HGLOBAL hRes; 00035 LPWSTR lpName, lpStr; 00036 00037 if (hInst == NULL) 00038 { 00039 return -1; 00040 } 00041 00042 /* There are always blocks of 16 strings */ 00043 lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1); 00044 00045 /* Find the string table block */ 00046 if ((hrSrc = FindResourceW(hInst, 00047 lpName, 00048 (LPWSTR)RT_STRING)) && 00049 (hRes = LoadResource(hInst, 00050 hrSrc)) && 00051 (lpStr = LockResource(hRes))) 00052 { 00053 UINT x; 00054 00055 /* Find the string we're looking for */ 00056 uID &= 0xF; /* position in the block, same as % 16 */ 00057 for (x = 0; x < uID; x++) 00058 { 00059 lpStr += (*lpStr) + 1; 00060 } 00061 00062 /* Found the string */ 00063 return (int)(*lpStr); 00064 } 00065 return -1; 00066 } 00067 00068 INT 00069 AllocAndLoadString(OUT LPWSTR *lpTarget, 00070 IN HINSTANCE hInst, 00071 IN UINT uID) 00072 { 00073 INT ln; 00074 00075 ln = LengthOfStrResource(hInst, 00076 uID); 00077 if (ln++ > 0) 00078 { 00079 (*lpTarget) = (LPWSTR)LocalAlloc(LMEM_FIXED, 00080 ln * sizeof(WCHAR)); 00081 if ((*lpTarget) != NULL) 00082 { 00083 INT Ret = LoadStringW(hInst, 00084 uID, 00085 *lpTarget, 00086 ln); 00087 if (!Ret) 00088 { 00089 LocalFree((HLOCAL)(*lpTarget)); 00090 } 00091 return Ret; 00092 } 00093 } 00094 return 0; 00095 } 00096 00097 DWORD 00098 LoadAndFormatString(IN HINSTANCE hInstance, 00099 IN UINT uID, 00100 OUT LPWSTR *lpTarget, 00101 ...) 00102 { 00103 DWORD Ret = 0; 00104 LPWSTR lpFormat; 00105 va_list lArgs; 00106 00107 if (AllocAndLoadString(&lpFormat, 00108 hInstance, 00109 uID) > 0) 00110 { 00111 va_start(lArgs, lpTarget); 00112 /* let's use FormatMessage to format it because it has the ability to 00113 allocate memory automatically */ 00114 Ret = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING, 00115 lpFormat, 00116 0, 00117 0, 00118 (LPWSTR)lpTarget, 00119 0, 00120 &lArgs); 00121 va_end(lArgs); 00122 00123 LocalFree((HLOCAL)lpFormat); 00124 } 00125 00126 return Ret; 00127 } 00128 00129 static const TCHAR AppRegSettings[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Volume Control"); 00130 static const TCHAR AppOptionsKey[] = TEXT("Options"); 00131 static const TCHAR LineStatesValue[] = TEXT("LineStates"); 00132 static const TCHAR StyleValue[] = TEXT("Style"); 00133 00134 HKEY hAppSettingsKey = NULL; 00135 00136 BOOL 00137 InitAppConfig(VOID) 00138 { 00139 return RegCreateKeyEx(HKEY_CURRENT_USER, 00140 AppRegSettings, 00141 0, 00142 NULL, 00143 REG_OPTION_NON_VOLATILE, 00144 KEY_READ | KEY_WRITE, 00145 NULL, 00146 &hAppSettingsKey, 00147 NULL) == ERROR_SUCCESS; 00148 } 00149 00150 VOID 00151 CloseAppConfig(VOID) 00152 { 00153 if (hAppSettingsKey != NULL) 00154 { 00155 RegCloseKey(hAppSettingsKey); 00156 hAppSettingsKey = NULL; 00157 } 00158 } 00159 00160 BOOL 00161 WriteLineConfig(IN LPTSTR szDeviceName, 00162 IN LPTSTR szLineName, 00163 IN PSNDVOL_REG_LINESTATE LineState, 00164 IN DWORD cbSize) 00165 { 00166 HKEY hLineKey; 00167 TCHAR szDevRegKey[MAX_PATH]; 00168 BOOL Ret = FALSE; 00169 00170 _stprintf(szDevRegKey, 00171 TEXT("%s\\%s"), 00172 szDeviceName, 00173 szLineName); 00174 00175 if (RegCreateKeyEx(hAppSettingsKey, 00176 szDevRegKey, 00177 0, 00178 NULL, 00179 REG_OPTION_NON_VOLATILE, 00180 KEY_READ | KEY_WRITE, 00181 NULL, 00182 &hLineKey, 00183 NULL) == ERROR_SUCCESS) 00184 { 00185 /* now update line states */ 00186 RegSetValueEx(hLineKey, LineStatesValue, 0, REG_BINARY, (const BYTE*)LineState, cbSize); 00187 Ret = TRUE; 00188 00189 RegCloseKey(hLineKey); 00190 } 00191 00192 return Ret; 00193 } 00194 00195 BOOL 00196 ReadLineConfig(IN LPTSTR szDeviceName, 00197 IN LPTSTR szLineName, 00198 IN LPTSTR szControlName, 00199 OUT DWORD *Flags) 00200 { 00201 HKEY hLineKey; 00202 DWORD Type; 00203 DWORD i, Size = 0; 00204 PSNDVOL_REG_LINESTATE LineStates = NULL; 00205 TCHAR szDevRegKey[MAX_PATH]; 00206 BOOL Ret = FALSE; 00207 00208 _stprintf(szDevRegKey, 00209 TEXT("%s\\%s"), 00210 szDeviceName, 00211 szLineName); 00212 00213 if (RegCreateKeyEx(hAppSettingsKey, 00214 szDevRegKey, 00215 0, 00216 NULL, 00217 REG_OPTION_NON_VOLATILE, 00218 KEY_READ | KEY_WRITE, 00219 NULL, 00220 &hLineKey, 00221 NULL) == ERROR_SUCCESS) 00222 { 00223 if (RegQueryValueEx(hLineKey, 00224 LineStatesValue, 00225 NULL, 00226 &Type, 00227 NULL, 00228 &Size) != ERROR_SUCCESS || 00229 Type != REG_BINARY || 00230 Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0)) 00231 { 00232 goto ExitClose; 00233 } 00234 00235 LineStates = HeapAlloc(GetProcessHeap(), 00236 HEAP_ZERO_MEMORY, 00237 Size); 00238 00239 if (LineStates != NULL) 00240 { 00241 if (RegQueryValueEx(hLineKey, 00242 LineStatesValue, 00243 NULL, 00244 &Type, 00245 (LPBYTE)LineStates, 00246 &Size) != ERROR_SUCCESS || 00247 Type != REG_BINARY || 00248 Size == 0 || (Size % sizeof(SNDVOL_REG_LINESTATE) != 0)) 00249 { 00250 goto ExitClose; 00251 } 00252 00253 /* try to find the control */ 00254 for (i = 0; i < Size / sizeof(SNDVOL_REG_LINESTATE); i++) 00255 { 00256 if (!_tcscmp(szControlName, 00257 LineStates[i].LineName)) 00258 { 00259 *Flags = LineStates[i].Flags; 00260 Ret = TRUE; 00261 break; 00262 } 00263 } 00264 } 00265 00266 ExitClose: 00267 HeapFree(GetProcessHeap(), 00268 0, 00269 LineStates); 00270 RegCloseKey(hLineKey); 00271 } 00272 00273 return Ret; 00274 } Generated on Mon May 28 2012 04:16:49 for ReactOS by
1.7.6.1
|