1 | /* $Id: internal.cpp,v 1.2 1999-09-18 15:57:10 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * MSACM32 library
|
---|
4 | *
|
---|
5 | * Copyright 1998 Patrik Stridvall
|
---|
6 | * Copyright 1999 Jens Wiessner
|
---|
7 | */
|
---|
8 |
|
---|
9 | #include <os2win.h>
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <stdlib.h>
|
---|
12 | #include <string.h>
|
---|
13 | #include <odinwrap.h>
|
---|
14 |
|
---|
15 | #include "winbase.h"
|
---|
16 | #include "winuser.h"
|
---|
17 | #include "winerror.h"
|
---|
18 | #include "driver.h"
|
---|
19 | #include "heapstring.h"
|
---|
20 | #include "mmsystem.h"
|
---|
21 | #include "msacm.h"
|
---|
22 | #include "msacmdrv.h"
|
---|
23 | #include "debugtools.h"
|
---|
24 |
|
---|
25 | /**********************************************************************/
|
---|
26 |
|
---|
27 | HANDLE MSACM_hHeap = (HANDLE) NULL;
|
---|
28 | PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
|
---|
29 | PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
|
---|
30 | INT WINAPI lstrncmpiA(LPCSTR,LPCSTR,INT);
|
---|
31 |
|
---|
32 |
|
---|
33 | /***********************************************************************
|
---|
34 | * MSACM_RegisterDriver32()
|
---|
35 | */
|
---|
36 | PWINE_ACMDRIVERID MSACM_RegisterDriver(
|
---|
37 | LPSTR pszDriverAlias, LPSTR pszFileName,
|
---|
38 | PWINE_ACMLOCALDRIVER pLocalDriver)
|
---|
39 | {
|
---|
40 | PWINE_ACMDRIVERID padid;
|
---|
41 | padid = (PWINE_ACMDRIVERID) HeapAlloc(
|
---|
42 | MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID)
|
---|
43 | );
|
---|
44 | padid->pszDriverAlias =
|
---|
45 | HEAP_strdupA(MSACM_hHeap, 0, pszDriverAlias);
|
---|
46 | padid->pszFileName =
|
---|
47 | HEAP_strdupA(MSACM_hHeap, 0, pszFileName);
|
---|
48 | padid->pACMLocalDriver = pLocalDriver;
|
---|
49 | padid->bEnabled = TRUE;
|
---|
50 | padid->pACMDriver = NULL;
|
---|
51 | padid->pNextACMDriverID = NULL;
|
---|
52 | padid->pPreviousACMDriverID =
|
---|
53 | MSACM_pLastACMDriverID;
|
---|
54 | MSACM_pLastACMDriverID = padid;
|
---|
55 | if(!MSACM_pFirstACMDriverID)
|
---|
56 | MSACM_pFirstACMDriverID = padid;
|
---|
57 |
|
---|
58 | return padid;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /***********************************************************************
|
---|
62 | * MSACM_RegisterAllDrivers32()
|
---|
63 | */
|
---|
64 | void MSACM_RegisterAllDrivers()
|
---|
65 | {
|
---|
66 | PWINE_ACMBUILTINDRIVER pbd;
|
---|
67 | LPSTR pszBuffer;
|
---|
68 | DWORD dwBufferLength;
|
---|
69 |
|
---|
70 | /* FIXME
|
---|
71 | * What if the user edits system.ini while the program is running?
|
---|
72 | * Does Windows handle that?
|
---|
73 | */
|
---|
74 | if(!MSACM_pFirstACMDriverID)
|
---|
75 | return;
|
---|
76 |
|
---|
77 | /* FIXME: Do not work! How do I determine the section length? */
|
---|
78 | dwBufferLength =
|
---|
79 | GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini");
|
---|
80 |
|
---|
81 | pszBuffer = (LPSTR) HeapAlloc(
|
---|
82 | MSACM_hHeap, 0, dwBufferLength
|
---|
83 | );
|
---|
84 | if(GetPrivateProfileSectionA(
|
---|
85 | "drivers32", pszBuffer, dwBufferLength, "system.ini"))
|
---|
86 | {
|
---|
87 | char *s = pszBuffer;
|
---|
88 | while(*s)
|
---|
89 | {
|
---|
90 | if(!lstrncmpiA("MSACM.", s, 6))
|
---|
91 | {
|
---|
92 | char *s2 = s;
|
---|
93 | while(*s2 != '\0' && *s2 != '=') s2++;
|
---|
94 | if(*s2)
|
---|
95 | {
|
---|
96 | *s2++='\0';
|
---|
97 | MSACM_RegisterDriver(s, s2, NULL);
|
---|
98 | }
|
---|
99 | }
|
---|
100 | s += lstrlenA(s) + 1; /* Either next char or \0 */
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* FIXME
|
---|
105 | * Check if any of the builtin driver was added
|
---|
106 | * when the external drivers was.
|
---|
107 | */
|
---|
108 |
|
---|
109 | pbd = MSACM_BuiltinDrivers;
|
---|
110 | while(pbd->pszDriverAlias)
|
---|
111 | {
|
---|
112 | PWINE_ACMLOCALDRIVER pld;
|
---|
113 | pld = (PWINE_ACMLOCALDRIVER) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMLOCALDRIVER));
|
---|
114 | pld->pfnDriverProc = pbd->pfnDriverProc;
|
---|
115 | MSACM_RegisterDriver(pbd->pszDriverAlias, NULL, pld);
|
---|
116 | pbd++;
|
---|
117 | }
|
---|
118 | HeapFree(MSACM_hHeap, 0, pszBuffer);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /***********************************************************************
|
---|
122 | * MSACM_UnregisterDriver32()
|
---|
123 | */
|
---|
124 | PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
|
---|
125 | {
|
---|
126 | PWINE_ACMDRIVERID pNextACMDriverID;
|
---|
127 |
|
---|
128 | if(p->pACMDriver)
|
---|
129 | acmDriverClose((HACMDRIVER) p->pACMDriver, 0);
|
---|
130 |
|
---|
131 | if(p->pszDriverAlias)
|
---|
132 | HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
|
---|
133 | if(p->pszFileName)
|
---|
134 | HeapFree(MSACM_hHeap, 0, p->pszFileName);
|
---|
135 | if(p->pACMLocalDriver)
|
---|
136 | HeapFree(MSACM_hHeap, 0, p->pACMLocalDriver);
|
---|
137 |
|
---|
138 | if(p->pPreviousACMDriverID)
|
---|
139 | p->pPreviousACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
|
---|
140 | if(p->pNextACMDriverID)
|
---|
141 | p->pNextACMDriverID->pPreviousACMDriverID = p->pPreviousACMDriverID;
|
---|
142 |
|
---|
143 | pNextACMDriverID = p->pNextACMDriverID;
|
---|
144 |
|
---|
145 | HeapFree(MSACM_hHeap, 0, p);
|
---|
146 |
|
---|
147 | return pNextACMDriverID;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /***********************************************************************
|
---|
151 | * MSACM_UnregisterAllDrivers32()
|
---|
152 | * FIXME
|
---|
153 | * Where should this function be called?
|
---|
154 | */
|
---|
155 | void MSACM_UnregisterAllDrivers()
|
---|
156 | {
|
---|
157 | PWINE_ACMDRIVERID p = MSACM_pFirstACMDriverID;
|
---|
158 | while(p) p = MSACM_UnregisterDriver(p);
|
---|
159 | }
|
---|
160 |
|
---|
161 | /***********************************************************************
|
---|
162 | * MSACM_GetDriverID32()
|
---|
163 | */
|
---|
164 | PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
|
---|
165 | {
|
---|
166 | return (PWINE_ACMDRIVERID) hDriverID;
|
---|
167 | }
|
---|
168 |
|
---|
169 | /***********************************************************************
|
---|
170 | * MSACM_GetDriver32()
|
---|
171 | */
|
---|
172 | PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
|
---|
173 | {
|
---|
174 | return (PWINE_ACMDRIVER) hDriver;
|
---|
175 | }
|
---|
176 |
|
---|
177 | /***********************************************************************
|
---|
178 | * MSACM_GetObj32()
|
---|
179 | */
|
---|
180 | PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj)
|
---|
181 | {
|
---|
182 | return (PWINE_ACMOBJ) hObj;
|
---|
183 | }
|
---|
184 |
|
---|
185 | /***********************************************************************
|
---|
186 | * MSACM_OpenDriverProc32
|
---|
187 | * FIXME
|
---|
188 | * This function should be integrated with OpenDriver,
|
---|
189 | * renamed and moved there.
|
---|
190 | */
|
---|
191 | HDRVR MSACM_OpenDriverProc(DRIVERPROC pfnDriverProc)
|
---|
192 | {
|
---|
193 | #if 0
|
---|
194 | LPDRIVERITEMA pDrvr;
|
---|
195 |
|
---|
196 | /* FIXME: This is a very bad solution */
|
---|
197 | pDrvr = (LPDRIVERITEMA) HeapAlloc(MSACM_hHeap, HEAP_ZERO_MEMORY, sizeof(DRIVERITEMA));
|
---|
198 | pDrvr->count = 1;
|
---|
199 | pDrvr->driverproc = pfnDriverProc;
|
---|
200 |
|
---|
201 | /* FIXME: Send DRV_OPEN among others to DriverProc */
|
---|
202 |
|
---|
203 | return (HDRVR) pDrvr;
|
---|
204 | #else
|
---|
205 | return (HDRVR) 0;
|
---|
206 | #endif
|
---|
207 | }
|
---|
208 |
|
---|
209 |
|
---|