Replaced a few internal functions by exported ones.
[wine] / dlls / msacm / internal.c
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2
3 /*
4  *      MSACM32 library
5  *
6  *      Copyright 1998  Patrik Stridvall
7  *                1999  Eric Pouech
8  */
9
10 #include <string.h>
11
12 #include "winbase.h"
13 #include "windef.h"
14 #include "wingdi.h"
15 #include "winuser.h"
16 #include "winerror.h"
17 #include "mmsystem.h"
18 #include "msacm.h"
19 #include "msacmdrv.h"
20 #include "wineacm.h"
21 #include "debugtools.h"
22
23 DEFAULT_DEBUG_CHANNEL(msacm);
24
25 /**********************************************************************/
26
27 HANDLE MSACM_hHeap = (HANDLE) NULL;
28 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
29 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
30
31 /***********************************************************************
32  *           MSACM_RegisterDriver() 
33  */
34 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
35                                        HINSTANCE hinstModule)
36
37     PWINE_ACMDRIVERID padid;
38
39     TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
40
41     padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
42     padid->obj.dwType = WINE_ACMOBJ_DRIVERID;
43     padid->obj.pACMDriverID = padid;
44     padid->pszDriverAlias = NULL;
45     if (pszDriverAlias)
46     {
47         padid->pszDriverAlias = HeapAlloc( MSACM_hHeap, 0, strlen(pszDriverAlias)+1 );
48         strcpy( padid->pszDriverAlias, pszDriverAlias );
49     }
50     padid->pszFileName = NULL;
51     if (pszFileName)
52     {
53         padid->pszFileName = HeapAlloc( MSACM_hHeap, 0, strlen(pszFileName)+1 );
54         strcpy( padid->pszFileName, pszFileName );
55     }
56     padid->hInstModule = hinstModule;
57     padid->bEnabled = TRUE;
58     padid->pACMDriverList = NULL;
59     padid->pNextACMDriverID = NULL;
60     padid->pPrevACMDriverID = MSACM_pLastACMDriverID;
61     if (MSACM_pLastACMDriverID)
62         MSACM_pLastACMDriverID->pNextACMDriverID = padid;
63     MSACM_pLastACMDriverID = padid;
64     if (!MSACM_pFirstACMDriverID)
65         MSACM_pFirstACMDriverID = padid;
66     
67     return padid;
68 }
69
70 /***********************************************************************
71  *           MSACM_RegisterAllDrivers() 
72  */
73 void MSACM_RegisterAllDrivers(void)
74 {
75     LPSTR pszBuffer;
76     DWORD dwBufferLength;
77
78     /* FIXME 
79      *  What if the user edits system.ini while the program is running?
80      *  Does Windows handle that?
81      */
82     if (MSACM_pFirstACMDriverID)
83         return;
84     
85     /* FIXME: Do not work! How do I determine the section length? */
86     dwBufferLength = 1024;
87 /* EPP  GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */
88     
89     pszBuffer = (LPSTR) HeapAlloc(MSACM_hHeap, 0, dwBufferLength);
90     if (GetPrivateProfileSectionA("drivers32", pszBuffer, dwBufferLength, "system.ini")) {
91         char* s = pszBuffer;
92         while (*s) {
93             if (!strncasecmp("MSACM.", s, 6)) {
94                 char *s2 = s;
95                 while (*s2 != '\0' && *s2 != '=') s2++;
96                 if (*s2) {
97                     *s2 = '\0';
98                     MSACM_RegisterDriver(s, s2 + 1, 0);
99                     *s2 = '=';
100                 }
101             }  
102             s += strlen(s) + 1; /* Either next char or \0 */
103         }
104     }
105     
106     HeapFree(MSACM_hHeap, 0, pszBuffer);
107
108     MSACM_RegisterDriver("msacm32.dll", "msacm32.dll", 0);
109 }
110
111 /***********************************************************************
112  *           MSACM_UnregisterDriver()
113  */
114 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
115 {
116     PWINE_ACMDRIVERID pNextACMDriverID;
117     
118     while (p->pACMDriverList)
119         acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
120     
121     if (p->pszDriverAlias)
122         HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
123     if (p->pszFileName)
124         HeapFree(MSACM_hHeap, 0, p->pszFileName);
125     
126     if (p == MSACM_pFirstACMDriverID)
127         MSACM_pFirstACMDriverID = p->pNextACMDriverID;
128     if (p == MSACM_pLastACMDriverID)
129         MSACM_pLastACMDriverID = p->pPrevACMDriverID;
130
131     if (p->pPrevACMDriverID)
132         p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
133     if (p->pNextACMDriverID)
134         p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
135     
136     pNextACMDriverID = p->pNextACMDriverID;
137     
138     HeapFree(MSACM_hHeap, 0, p);
139     
140     return pNextACMDriverID;
141 }
142
143 /***********************************************************************
144  *           MSACM_UnregisterAllDrivers()
145  * FIXME
146  *   Where should this function be called?
147  */
148 void MSACM_UnregisterAllDrivers(void)
149 {
150     PWINE_ACMDRIVERID p;
151
152     for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p));
153 }
154
155 /***********************************************************************
156  *           MSACM_GetObj()
157  */
158 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj, DWORD type)
159 {
160     PWINE_ACMOBJ        pao = (PWINE_ACMOBJ)hObj;
161
162     if (pao == NULL || IsBadReadPtr(pao, sizeof(WINE_ACMOBJ)) ||
163         ((type != WINE_ACMOBJ_DONTCARE) && (type != pao->dwType)))
164         return NULL;
165     return pao;
166 }
167
168 /***********************************************************************
169  *           MSACM_GetDriverID() 
170  */
171 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
172 {
173     return (PWINE_ACMDRIVERID)MSACM_GetObj((HACMOBJ)hDriverID, WINE_ACMOBJ_DRIVERID);
174 }
175
176 /***********************************************************************
177  *           MSACM_GetDriver()
178  */
179 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
180 {
181     return (PWINE_ACMDRIVER)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_DRIVER);
182 }
183
184 /***********************************************************************
185  *           MSACM_Message()
186  */
187 MMRESULT MSACM_Message(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
188 {
189     PWINE_ACMDRIVER     pad = MSACM_GetDriver(had);
190
191     return pad ? SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2) : MMSYSERR_INVALHANDLE;
192 }