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