- fixed reported bugs
[wine.git] / dlls / msacm32 / internal.c
blobc1db5202296798584ff178805d95bba9ce4381ed
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 /*
4 * MSACM32 library
6 * Copyright 1998 Patrik Stridvall
7 * 1999 Eric Pouech
8 */
10 #include <string.h>
12 #include "winbase.h"
13 #include "windef.h"
14 #include "wingdi.h"
15 #include "winuser.h"
16 #include "winerror.h"
17 #include "driver.h"
18 #include "heap.h"
19 #include "mmsystem.h"
20 #include "msacm.h"
21 #include "msacmdrv.h"
22 #include "wineacm.h"
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(msacm)
27 /**********************************************************************/
29 HANDLE MSACM_hHeap = (HANDLE) NULL;
30 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
31 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
33 /***********************************************************************
34 * MSACM_RegisterDriver32()
36 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
37 HINSTANCE hinstModule)
39 PWINE_ACMDRIVERID padid;
41 TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
43 padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
44 padid->pszDriverAlias = HEAP_strdupA(MSACM_hHeap, 0, pszDriverAlias);
45 padid->pszFileName = HEAP_strdupA(MSACM_hHeap, 0, pszFileName);
46 padid->hInstModule = hinstModule;
47 padid->bEnabled = TRUE;
48 padid->pACMDriverList = NULL;
49 padid->pNextACMDriverID = NULL;
50 padid->pPrevACMDriverID = MSACM_pLastACMDriverID;
51 if (MSACM_pLastACMDriverID)
52 MSACM_pLastACMDriverID->pNextACMDriverID = padid;
53 MSACM_pLastACMDriverID = padid;
54 if (!MSACM_pFirstACMDriverID)
55 MSACM_pFirstACMDriverID = padid;
57 return padid;
60 /***********************************************************************
61 * MSACM_RegisterAllDrivers32()
63 void MSACM_RegisterAllDrivers(void)
65 LPSTR pszBuffer;
66 DWORD dwBufferLength;
68 /* FIXME
69 * What if the user edits system.ini while the program is running?
70 * Does Windows handle that?
72 if (MSACM_pFirstACMDriverID)
73 return;
75 /* FIXME: Do not work! How do I determine the section length? */
76 dwBufferLength = 1024;
77 /* EPP GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */
79 pszBuffer = (LPSTR) HeapAlloc(MSACM_hHeap, 0, dwBufferLength);
80 if (GetPrivateProfileSectionA("drivers32", pszBuffer, dwBufferLength, "system.ini")) {
81 char* s = pszBuffer;
82 while (*s) {
83 if (!lstrncmpiA("MSACM.", s, 6)) {
84 char *s2 = s;
85 while (*s2 != '\0' && *s2 != '=') s2++;
86 if (*s2) {
87 *s2++ = '\0';
88 MSACM_RegisterDriver(s, s2, 0);
91 s += lstrlenA(s) + 1; /* Either next char or \0 */
95 HeapFree(MSACM_hHeap, 0, pszBuffer);
98 /***********************************************************************
99 * MSACM_UnregisterDriver32()
101 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
103 PWINE_ACMDRIVERID pNextACMDriverID;
105 while (p->pACMDriverList)
106 acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
108 if (p->pszDriverAlias)
109 HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
110 if (p->pszFileName)
111 HeapFree(MSACM_hHeap, 0, p->pszFileName);
113 if (p == MSACM_pFirstACMDriverID)
114 MSACM_pFirstACMDriverID = p->pNextACMDriverID;
115 if (p == MSACM_pLastACMDriverID)
116 MSACM_pLastACMDriverID = p->pPrevACMDriverID;
118 if (p->pPrevACMDriverID)
119 p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
120 if (p->pNextACMDriverID)
121 p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
123 pNextACMDriverID = p->pNextACMDriverID;
125 HeapFree(MSACM_hHeap, 0, p);
127 return pNextACMDriverID;
130 /***********************************************************************
131 * MSACM_UnregisterAllDrivers32()
132 * FIXME
133 * Where should this function be called?
135 void MSACM_UnregisterAllDrivers(void)
137 PWINE_ACMDRIVERID p;
139 for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p));
142 /***********************************************************************
143 * MSACM_GetDriverID32()
145 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
147 return (PWINE_ACMDRIVERID)hDriverID;
150 /***********************************************************************
151 * MSACM_GetDriver32()
153 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
155 return (PWINE_ACMDRIVER)hDriver;
158 /***********************************************************************
159 * MSACM_GetObj32()
161 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj)
163 return (PWINE_ACMOBJ)hObj;