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