[WINMM]
[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 "winemm.h"
20
21 WINE_DEFAULT_DEBUG_CHANNEL(winmm);
22
23 BOOL LoadRegistryMMEDrivers(char* key)
24 {
25 INT driver_count = 0;
26 INT driver_index = 0;
27 HKEY drivers_key;
28
29 DWORD value_name_length = 256;
30 char value_name[256];
31
32 DWORD value_data_length = 256;
33 char value_data[256];
34
35 DWORD value_type;
36
37 if ( RegOpenKeyA(HKEY_LOCAL_MACHINE, key, &drivers_key) != ERROR_SUCCESS )
38 {
39 TRACE("ERROR: Could not open: HKEY_LOCAL_MACHINE\\%s\n", key);
40 return 0;
41 }
42
43 while ( RegEnumValue(drivers_key,
44 driver_index,
45 value_name,
46 &value_name_length,
47 NULL,
48 &value_type,
49 (LPBYTE)value_data,
50 &value_data_length) == ERROR_SUCCESS )
51 {
52 BOOL valid_driver = FALSE;
53 BOOL is_mapper = FALSE;
54
55 if ( value_type == REG_SZ )
56 {
57 /* We look for mappers first so they don't match
58 something else later on! */
59
60 if ( ! stricmp("wavemapper", value_name) )
61 {
62 TRACE("Found a Wave-mapper: %s\n", value_data);
63 valid_driver = TRUE;
64 is_mapper = TRUE;
65 driver_count ++;
66 }
67 else if ( ! stricmp("midimapper", value_name) )
68 {
69 TRACE("Found a MIDI-mapper: %s\n", value_data);
70 valid_driver = TRUE;
71 is_mapper = TRUE;
72 driver_count ++;
73 }
74 else if ( ! _strnicmp("wave", value_name, 4) )
75 {
76 TRACE("Found a Wave driver: %s\n", value_data);
77 valid_driver = TRUE;
78 driver_count ++;
79 }
80 else if ( ! _strnicmp("midi", value_name, 4) )
81 {
82 TRACE("Found a MIDI driver: %s\n", value_data);
83 valid_driver = TRUE;
84 driver_count ++;
85 }
86 else if ( ! _strnicmp("mixer", value_name, 5) )
87 {
88 TRACE("Found a mixer driver: %s\n", value_data);
89 valid_driver = TRUE;
90 driver_count ++;
91 }
92 else if ( ! _strnicmp("aux", value_name, 4) )
93 {
94 TRACE("Found an aux driver: %s\n", value_data);
95 valid_driver = TRUE;
96 driver_count ++;
97 }
98 else
99 {
100 TRACE("Not supported: %s\n", value_data);
101 }
102
103 /* If we have a valid driver now, we get it "installed" in
104 winmm itself so it can be used */
105
106 if ( valid_driver )
107 {
108 if ( ! MMDRV_Install(value_name, value_data, is_mapper) )
109 {
110 TRACE("FAILED when initializing %s\n", value_data);
111 }
112 }
113 }
114 else
115 {
116 TRACE("Invalid data format\n");
117 }
118
119 /* Reinitialize */
120 value_name_length = 256;
121 value_data_length = 256;
122 memset(value_name, 0, value_name_length);
123 memset(value_data, 0, value_data_length);
124
125 driver_index ++;
126 }
127
128 TRACE("Found a total of %d drivers\n", driver_count);
129
130 return driver_count;
131 }