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