xref: /reactos/dll/win32/winmm/registry.c (revision 9393fc32)
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     char wavemapper[256] = { 0 };
36     char midimapper[256] = { 0 };
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                          (LPBYTE)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                 /* Delay loading Wave mapper driver */
67                 strcpy(wavemapper, value_data);
68                 is_mapper = TRUE;
69                 driver_count ++;
70             }
71             else if ( ! stricmp("midimapper", value_name) )
72             {
73                 TRACE("Found a MIDI-mapper: %s\n", value_data);
74                 /* Delay loading MIDI mapper driver */
75                 strcpy(midimapper, value_data);
76                 is_mapper = TRUE;
77                 driver_count ++;
78             }
79             else if ( ! _strnicmp("wave", value_name, 4) )
80             {
81                 TRACE("Found a Wave driver: %s\n", value_data);
82                 valid_driver = TRUE;
83                 driver_count ++;
84             }
85             else if ( ! _strnicmp("midi", value_name, 4) )
86             {
87                 TRACE("Found a MIDI driver: %s\n", value_data);
88                 valid_driver = TRUE;
89                 driver_count ++;
90             }
91             else if ( ! _strnicmp("mixer", value_name, 5) )
92             {
93                 TRACE("Found a mixer driver: %s\n", value_data);
94                 valid_driver = TRUE;
95                 driver_count ++;
96             }
97             else if ( ! _strnicmp("aux", value_name, 4) )
98             {
99                 TRACE("Found an aux driver: %s\n", value_data);
100                 valid_driver = TRUE;
101                 driver_count ++;
102             }
103             else
104             {
105                 TRACE("Not supported: %s\n", value_data);
106             }
107 
108             /* If we have a valid driver now, we get it "installed" in
109                winmm itself so it can be used */
110 
111             if ( valid_driver )
112             {
113                 if ( ! MMDRV_Install(value_name, value_data, is_mapper) )
114                 {
115                     TRACE("FAILED when initializing %s\n", value_data);
116                 }
117             }
118         }
119         else
120         {
121             TRACE("Invalid data format\n");
122         }
123 
124         /* Reinitialize */
125         value_name_length = 256;
126         value_data_length = 256;
127         memset(value_name, 0, value_name_length);
128         memset(value_data, 0, value_data_length);
129 
130         driver_index ++;
131     }
132 
133     /* Finally load mapper drivers, since they expect device drivers already loaded */
134     if (*wavemapper)
135     {
136         if (!MMDRV_Install("wavemapper", wavemapper, TRUE))
137         {
138             TRACE("FAILED when initializing %s\n", wavemapper);
139         }
140     }
141 
142     if (*midimapper)
143     {
144         if (!MMDRV_Install("midimapper", midimapper, TRUE))
145         {
146             TRACE("FAILED when initializing %s\n", midimapper);
147         }
148     }
149 
150     TRACE("Found a total of %d drivers\n", driver_count);
151 
152     return driver_count;
153 }
154