9a6c175a9ff1f546490368b463137bab16275627
[reactos.git] / sdk / lib / drivers / sound / mment4 / registry.c
1 /*
2 * PROJECT: ReactOS Sound System "MME Buddy" NT4 Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/drivers/sound/mment4/registry.c
5 *
6 * PURPOSE: Registry operation helper for audio device drivers.
7 *
8 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
9 */
10
11 #include "precomp.h"
12
13 #include <mmebuddy_debug.h>
14
15 /*
16 Open the parameters key of a sound driver.
17 NT4 only.
18 */
19 MMRESULT
20 OpenSoundDriverParametersRegKey(
21 IN LPWSTR ServiceName,
22 OUT PHKEY KeyHandle)
23 {
24 ULONG KeyLength;
25 PWCHAR ParametersKeyName;
26
27 VALIDATE_MMSYS_PARAMETER( ServiceName );
28 VALIDATE_MMSYS_PARAMETER( KeyHandle );
29
30 /* Work out how long the string will be */
31 KeyLength = wcslen(REG_SERVICES_KEY_NAME_U) + 1
32 + wcslen(ServiceName) + 1
33 + wcslen(REG_PARAMETERS_KEY_NAME_U);
34
35 /* Allocate memory for the string */
36 ParametersKeyName = AllocateWideString(KeyLength);
37
38 if ( ! ParametersKeyName )
39 return MMSYSERR_NOMEM;
40
41 /* Construct the registry path */
42 wsprintf(ParametersKeyName,
43 L"%s\\%s\\%s",
44 REG_SERVICES_KEY_NAME_U,
45 ServiceName,
46 REG_PARAMETERS_KEY_NAME_U);
47
48 SND_TRACE(L"Opening reg key: %wS\n", ParametersKeyName);
49
50 /* Perform the open */
51 if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
52 ParametersKeyName,
53 0,
54 KEY_READ,
55 KeyHandle) != ERROR_SUCCESS )
56 {
57 /* Couldn't open the key */
58 SND_ERR(L"Failed to open reg key: %wS\n", ParametersKeyName);
59 FreeMemory(ParametersKeyName);
60 return MMSYSERR_ERROR;
61 }
62
63 FreeMemory(ParametersKeyName);
64
65 return MMSYSERR_NOERROR;
66 }
67
68 /*
69 Open one of the Device sub-keys belonging to the sound driver.
70 NT4 only.
71 */
72 MMRESULT
73 OpenSoundDeviceRegKey(
74 IN LPWSTR ServiceName,
75 IN DWORD DeviceIndex,
76 OUT PHKEY KeyHandle)
77 {
78 DWORD PathLength;
79 PWCHAR RegPath;
80
81 VALIDATE_MMSYS_PARAMETER( ServiceName );
82 VALIDATE_MMSYS_PARAMETER( KeyHandle );
83
84 /*
85 Work out the space required to hold the path:
86
87 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
88 sndblst\
89 Parameters\
90 Device123\
91 */
92 PathLength = wcslen(REG_SERVICES_KEY_NAME_U) + 1
93 + wcslen(ServiceName) + 1
94 + wcslen(REG_PARAMETERS_KEY_NAME_U) + 1
95 + wcslen(REG_DEVICE_KEY_NAME_U)
96 + GetDigitCount(DeviceIndex);
97
98 /* Allocate storage for the string */
99 RegPath = AllocateWideString(PathLength);
100
101 if ( ! RegPath )
102 {
103 return MMSYSERR_NOMEM;
104 }
105
106 /* Write the path */
107 wsprintf(RegPath,
108 L"%ls\\%ls\\%ls\\%ls%d",
109 REG_SERVICES_KEY_NAME_U,
110 ServiceName,
111 REG_PARAMETERS_KEY_NAME_U,
112 REG_DEVICE_KEY_NAME_U,
113 DeviceIndex);
114
115 SND_TRACE(L"Opening reg key: %wS\n", RegPath);
116
117 /* Perform the open */
118 if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
119 RegPath,
120 0,
121 KEY_READ,
122 KeyHandle) != ERROR_SUCCESS )
123 {
124 /* Couldn't open the key */
125 SND_ERR(L"Failed to open reg key: %wS\n", RegPath);
126 FreeMemory(RegPath);
127 return MMSYSERR_ERROR;
128 }
129
130 FreeMemory(RegPath);
131
132 return MMSYSERR_NOERROR;
133 }