1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
6 * Copyright 1998 Patrik Stridvall
21 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(msacm);
25 /**********************************************************************/
27 HANDLE MSACM_hHeap = (HANDLE) NULL;
28 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
29 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
31 /***********************************************************************
32 * MSACM_RegisterDriver()
34 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
35 HINSTANCE hinstModule)
37 PWINE_ACMDRIVERID padid;
39 TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
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;
47 padid->pszDriverAlias = HeapAlloc( MSACM_hHeap, 0, strlen(pszDriverAlias)+1 );
48 strcpy( padid->pszDriverAlias, pszDriverAlias );
50 padid->pszFileName = NULL;
53 padid->pszFileName = HeapAlloc( MSACM_hHeap, 0, strlen(pszFileName)+1 );
54 strcpy( padid->pszFileName, pszFileName );
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;
70 /***********************************************************************
71 * MSACM_RegisterAllDrivers()
73 void MSACM_RegisterAllDrivers(void)
79 * What if the user edits system.ini while the program is running?
80 * Does Windows handle that?
82 if (MSACM_pFirstACMDriverID)
85 /* FIXME: Do not work! How do I determine the section length? */
86 dwBufferLength = 1024;
87 /* EPP GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */
89 pszBuffer = (LPSTR) HeapAlloc(MSACM_hHeap, 0, dwBufferLength);
90 if (GetPrivateProfileSectionA("drivers32", pszBuffer, dwBufferLength, "system.ini")) {
93 if (!strncasecmp("MSACM.", s, 6)) {
95 while (*s2 != '\0' && *s2 != '=') s2++;
98 MSACM_RegisterDriver(s, s2 + 1, 0);
102 s += strlen(s) + 1; /* Either next char or \0 */
106 HeapFree(MSACM_hHeap, 0, pszBuffer);
108 MSACM_RegisterDriver("msacm32.dll", "msacm32.dll", 0);
111 /***********************************************************************
112 * MSACM_UnregisterDriver()
114 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
116 PWINE_ACMDRIVERID pNextACMDriverID;
118 while (p->pACMDriverList)
119 acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
121 if (p->pszDriverAlias)
122 HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
124 HeapFree(MSACM_hHeap, 0, p->pszFileName);
126 if (p == MSACM_pFirstACMDriverID)
127 MSACM_pFirstACMDriverID = p->pNextACMDriverID;
128 if (p == MSACM_pLastACMDriverID)
129 MSACM_pLastACMDriverID = p->pPrevACMDriverID;
131 if (p->pPrevACMDriverID)
132 p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
133 if (p->pNextACMDriverID)
134 p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
136 pNextACMDriverID = p->pNextACMDriverID;
138 HeapFree(MSACM_hHeap, 0, p);
140 return pNextACMDriverID;
143 /***********************************************************************
144 * MSACM_UnregisterAllDrivers()
146 * Where should this function be called?
148 void MSACM_UnregisterAllDrivers(void)
152 for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p));
155 /***********************************************************************
158 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj, DWORD type)
160 PWINE_ACMOBJ pao = (PWINE_ACMOBJ)hObj;
162 if (pao == NULL || IsBadReadPtr(pao, sizeof(WINE_ACMOBJ)) ||
163 ((type != WINE_ACMOBJ_DONTCARE) && (type != pao->dwType)))
168 /***********************************************************************
169 * MSACM_GetDriverID()
171 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
173 return (PWINE_ACMDRIVERID)MSACM_GetObj((HACMOBJ)hDriverID, WINE_ACMOBJ_DRIVERID);
176 /***********************************************************************
179 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
181 return (PWINE_ACMDRIVER)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_DRIVER);
184 /***********************************************************************
187 MMRESULT MSACM_Message(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
189 PWINE_ACMDRIVER pad = MSACM_GetDriver(had);
191 return pad ? SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2) : MMSYSERR_INVALHANDLE;