- New implementation of SendMessage, ReceiveMessage, ReplyMessage functions
[wine] / dlls / msacm32 / internal.c
1 /*
2  *      MSACM32 library
3  *
4  *      Copyright 1998  Patrik Stridvall
5  */
6
7 #include "winbase.h"
8 #include "winuser.h"
9 #include "winerror.h"
10 #include "wintypes.h"
11 #include "debug.h"
12 #include "driver.h"
13 #include "heap.h"
14 #include "mmsystem.h"
15 #include "msacm.h"
16 #include "msacmdrv.h"
17
18 /**********************************************************************/
19
20 HANDLE32 MSACM_hHeap32 = (HANDLE32) NULL;
21 PWINE_ACMDRIVERID32 MSACM_pFirstACMDriverID32 = NULL;
22 PWINE_ACMDRIVERID32 MSACM_pLastACMDriverID32 = NULL;
23
24 /***********************************************************************
25  *           MSACM_RegisterDriver32() 
26  */
27 PWINE_ACMDRIVERID32 MSACM_RegisterDriver32(
28   LPSTR pszDriverAlias, LPSTR pszFileName,
29   PWINE_ACMLOCALDRIVER32 pLocalDriver)
30 {
31   PWINE_ACMDRIVERID32 padid;
32   padid = (PWINE_ACMDRIVERID32) HeapAlloc(
33     MSACM_hHeap32, 0, sizeof(WINE_ACMDRIVERID32)
34   );
35   padid->pszDriverAlias = 
36     HEAP_strdupA(MSACM_hHeap32, 0, pszDriverAlias);
37   padid->pszFileName = 
38     HEAP_strdupA(MSACM_hHeap32, 0, pszFileName);
39   padid->pACMLocalDriver = pLocalDriver; 
40   padid->bEnabled = TRUE;
41   padid->pACMDriver = NULL;
42   padid->pNextACMDriverID = NULL;
43   padid->pPreviousACMDriverID = 
44     MSACM_pLastACMDriverID32;
45   MSACM_pLastACMDriverID32 = padid;
46   if(!MSACM_pFirstACMDriverID32)
47     MSACM_pFirstACMDriverID32 = padid;
48
49   return padid;
50 }
51
52 /***********************************************************************
53  *           MSACM_RegisterAllDrivers32() 
54  */
55 void MSACM_RegisterAllDrivers32()
56 {
57   PWINE_ACMBUILTINDRIVER32 pbd;
58   LPSTR pszBuffer;
59   DWORD dwBufferLength;
60
61   /* FIXME 
62    *  What if the user edits system.ini while the program is running?
63    *  Does Windows handle that?
64    */
65   if(!MSACM_pFirstACMDriverID32)
66     return;
67
68   /* FIXME: Do not work! How do I determine the section length? */
69   dwBufferLength = 
70     GetPrivateProfileSection32A("drivers32", NULL, 0, "system.ini");
71
72   pszBuffer = (LPSTR) HeapAlloc(
73     MSACM_hHeap32, 0, dwBufferLength
74   );
75   if(GetPrivateProfileSection32A(
76     "drivers32", pszBuffer, dwBufferLength, "system.ini"))
77     {
78       char *s = pszBuffer;
79       while(*s)
80         {
81           if(!lstrncmpi32A("MSACM.", s, 6))
82             {
83               char *s2 = s;
84               while(*s2 != '\0' && *s2 != '=') s2++;
85               if(*s2)
86                 {
87                   *s2++='\0';
88                   MSACM_RegisterDriver32(s, s2, NULL);
89                 }
90             }  
91           s += lstrlen32A(s) + 1; /* Either next char or \0 */
92         }
93     }
94
95   /* FIXME
96    *   Check if any of the builtin driver was added
97    *   when the external drivers was. 
98    */
99
100   pbd = MSACM_BuiltinDrivers32;
101   while(pbd->pszDriverAlias)
102     {
103       PWINE_ACMLOCALDRIVER32 pld;
104       pld = HeapAlloc(MSACM_hHeap32, 0, sizeof(WINE_ACMLOCALDRIVER32));
105       pld->pfnDriverProc = pbd->pfnDriverProc;
106       MSACM_RegisterDriver32(pbd->pszDriverAlias, NULL, pld);
107       pbd++;
108     }
109    HeapFree(MSACM_hHeap32, 0, pszBuffer);
110 }
111
112 /***********************************************************************
113  *           MSACM_UnregisterDriver32()
114  */
115 PWINE_ACMDRIVERID32 MSACM_UnregisterDriver32(PWINE_ACMDRIVERID32 p)
116 {
117   PWINE_ACMDRIVERID32 pNextACMDriverID;
118
119   if(p->pACMDriver)
120     acmDriverClose32((HACMDRIVER32) p->pACMDriver, 0);
121
122   if(p->pszDriverAlias)
123     HeapFree(MSACM_hHeap32, 0, p->pszDriverAlias);
124   if(p->pszFileName)
125     HeapFree(MSACM_hHeap32, 0, p->pszFileName);
126   if(p->pACMLocalDriver)
127     HeapFree(MSACM_hHeap32, 0, p->pACMLocalDriver);
128
129   if(p->pPreviousACMDriverID)
130     p->pPreviousACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
131   if(p->pNextACMDriverID)
132     p->pNextACMDriverID->pPreviousACMDriverID = p->pPreviousACMDriverID;
133
134   pNextACMDriverID = p->pNextACMDriverID;
135
136   HeapFree(MSACM_hHeap32, 0, p);
137
138   return pNextACMDriverID;
139 }
140
141 /***********************************************************************
142  *           MSACM_UnregisterAllDrivers32()
143  * FIXME
144  *   Where should this function be called?
145  */
146 void MSACM_UnregisterAllDrivers32()
147 {
148   PWINE_ACMDRIVERID32 p = MSACM_pFirstACMDriverID32;
149   while(p) p = MSACM_UnregisterDriver32(p);
150 }
151
152 /***********************************************************************
153  *           MSACM_GetDriverID32() 
154  */
155 PWINE_ACMDRIVERID32 MSACM_GetDriverID32(HACMDRIVERID32 hDriverID)
156 {
157   return (PWINE_ACMDRIVERID32) hDriverID;
158 }
159
160 /***********************************************************************
161  *           MSACM_GetDriver32()
162  */
163 PWINE_ACMDRIVER32 MSACM_GetDriver32(HACMDRIVER32 hDriver)
164 {
165   return (PWINE_ACMDRIVER32) hDriver;
166 }
167
168 /***********************************************************************
169  *           MSACM_GetObj32()
170  */
171 PWINE_ACMOBJ32 MSACM_GetObj32(HACMOBJ32 hObj)
172 {
173   return (PWINE_ACMOBJ32) hObj;
174 }
175
176 /***********************************************************************
177  *           MSACM_OpenDriverProc32
178  * FIXME
179  *  This function should be integrated with OpenDriver,
180  *  renamed and moved there.
181  */
182 HDRVR32 MSACM_OpenDriverProc32(DRIVERPROC32 pfnDriverProc)
183 {
184 #if 0
185   LPDRIVERITEM32A pDrvr;
186
187   /* FIXME: This is a very bad solution */
188   pDrvr = (LPDRIVERITEM32A) HeapAlloc(MSACM_hHeap32, HEAP_ZERO_MEMORY, sizeof(DRIVERITEM32A));
189   pDrvr->count = 1;
190   pDrvr->driverproc = pfnDriverProc;
191   
192   /* FIXME: Send DRV_OPEN among others to DriverProc */
193
194   return (HDRVR32) pDrvr;
195 #else
196   return (HDRVR32) 0;
197 #endif
198 }
199
200
201