4ffa6132b976d238c6e0955b4c52b7dd0cdb3764
[reactos.git] / reactos / dll / win32 / winmm / registry.c
1 /*
2 MME User-Mode Driver Support
3 (c) Andrew Greenwood, 2007.
4
5 This is intended for use with WINE's winmm.dll to allow it to find
6 and load appropriate drivers from the correct (Windows) registry keys.
7
8 By default, WINE's winmm.dll will look in:
9 HKEY_CURRENT_USER\Software\Wine\Drivers
10
11 Here it determines the driver to load based on a value called "Audio".
12
13 Windows NT stores a list of drivers in:
14 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Drivers32
15
16 TODO: Handle system.ini
17 */
18
19 #include <windows.h>
20 #include "winemm.h"
21 #include "wine/debug.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
24
25 BOOL LoadRegistryMMEDrivers(char* key)
26 {
27 INT driver_count = 0;
28 INT driver_index = 0;
29 HKEY drivers_key;
30 BOOL ret;
31
32 DWORD value_name_length = 256;
33 char value_name[value_name_length];
34
35 DWORD value_data_length = 256;
36 char value_data[value_data_length];
37
38 DWORD value_type;
39
40 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, key, &drivers_key) != ERROR_SUCCESS )
41 {
42 TRACE("ERROR: Could not open: HKEY_LOCAL_MACHINE\\%s\n", key);
43 return 0;
44 }
45
46 while ( RegEnumValue(drivers_key,
47 driver_index,
48 value_name,
49 &value_name_length,
50 NULL,
51 &value_type,
52 value_data,
53 &value_data_length) == ERROR_SUCCESS )
54 {
55 BOOL valid_driver = FALSE;
56 BOOL is_mapper = FALSE;
57
58 if ( value_type == REG_SZ )
59 {
60 /* We look for mappers first so they don't match
61 something else later on! */
62
63 if ( ! stricmp("wavemapper", value_name) )
64 {
65 TRACE("Found a Wave-mapper: %s\n", value_data);
66 valid_driver = TRUE;
67 is_mapper = TRUE;
68 driver_count ++;
69 }
70 else if ( ! stricmp("midimapper", value_name) )
71 {
72 TRACE("Found a MIDI-mapper: %s\n", value_data);
73 valid_driver = TRUE;
74 is_mapper = TRUE;
75 driver_count ++;
76 }
77 else if ( ! strnicmp("wave", value_name, 4) )
78 {
79 TRACE("Found a Wave driver: %s\n", value_data);
80 valid_driver = TRUE;
81 driver_count ++;
82 }
83 else if ( ! strnicmp("midi", value_name, 4) )
84 {
85 TRACE("Found a MIDI driver: %s\n", value_data);
86 valid_driver = TRUE;
87 driver_count ++;
88 }
89 else if ( ! strnicmp("mixer", value_name, 5) )
90 {
91 TRACE("Found a mixer driver: %s\n", value_data);
92 valid_driver = TRUE;
93 driver_count ++;
94 }
95 else if ( ! strnicmp("aux", value_name, 4) )
96 {
97 TRACE("Found an aux driver: %s\n", value_data);
98 valid_driver = TRUE;
99 driver_count ++;
100 }
101 else
102 {
103 TRACE("Not supported: %s\n", value_data);
104 }
105
106 /* If we have a valid driver now, we get it "installed" in
107 winmm itself so it can be used */
108
109 if ( valid_driver )
110 {
111 if ( ! MMDRV_Install(value_name, value_data, is_mapper) )
112 {
113 TRACE("FAILED when initializing %s\n", value_data);
114 }
115 }
116 }
117 else
118 {
119 TRACE("Invalid data format\n");
120 }
121
122 /* Reinitialize */
123 value_name_length = 256;
124 value_data_length = 256;
125 memset(value_name, 0, value_name_length);
126 memset(value_data, 0, value_data_length);
127
128 driver_index ++;
129 }
130
131 TRACE("Found a total of %d drivers\n", driver_count);
132
133 return driver_count;
134 }