Fixed the displaying of the FOURCC codes in _dump_pixelformat.
[wine] / dlls / msacm / internal.c
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 "heap.h"
18 #include "mmsystem.h"
19 #include "msacm.h"
20 #include "msacmdrv.h"
21 #include "wineacm.h"
22 #include "debugtools.h"
23
24 DEFAULT_DEBUG_CHANNEL(msacm)    
25
26 /**********************************************************************/
27
28 HANDLE MSACM_hHeap = (HANDLE) NULL;
29 PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
30 PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
31
32 /***********************************************************************
33  *           MSACM_RegisterDriver32() 
34  */
35 PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
36                                        HINSTANCE hinstModule)
37
38     PWINE_ACMDRIVERID padid;
39
40     TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule);
41
42     padid = (PWINE_ACMDRIVERID) HeapAlloc(MSACM_hHeap, 0, sizeof(WINE_ACMDRIVERID));
43     padid->pszDriverAlias = HEAP_strdupA(MSACM_hHeap, 0, pszDriverAlias);
44     padid->pszFileName = HEAP_strdupA(MSACM_hHeap, 0, pszFileName);
45     padid->hInstModule = hinstModule;
46     padid->bEnabled = TRUE;
47     padid->pACMDriverList = NULL;
48     padid->pNextACMDriverID = NULL;
49     padid->pPrevACMDriverID = MSACM_pLastACMDriverID;
50     if (MSACM_pLastACMDriverID)
51         MSACM_pLastACMDriverID->pNextACMDriverID = padid;
52     MSACM_pLastACMDriverID = padid;
53     if (!MSACM_pFirstACMDriverID)
54         MSACM_pFirstACMDriverID = padid;
55     
56     return padid;
57 }
58
59 /***********************************************************************
60  *           MSACM_RegisterAllDrivers32() 
61  */
62 void MSACM_RegisterAllDrivers(void)
63 {
64     LPSTR pszBuffer;
65     DWORD dwBufferLength;
66     
67     /* FIXME 
68      *  What if the user edits system.ini while the program is running?
69      *  Does Windows handle that?
70      */
71     if (MSACM_pFirstACMDriverID)
72         return;
73     
74     /* FIXME: Do not work! How do I determine the section length? */
75     dwBufferLength = 1024;
76 /* EPP  GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */
77     
78     pszBuffer = (LPSTR) HeapAlloc(MSACM_hHeap, 0, dwBufferLength);
79     if (GetPrivateProfileSectionA("drivers32", pszBuffer, dwBufferLength, "system.ini")) {
80         char* s = pszBuffer;
81         while (*s) {
82             if (!lstrncmpiA("MSACM.", s, 6)) {
83                 char *s2 = s;
84                 while (*s2 != '\0' && *s2 != '=') s2++;
85                 if (*s2) {
86                     *s2++ = '\0';
87                     MSACM_RegisterDriver(s, s2, 0);
88                 }
89             }  
90             s += strlen(s) + 1; /* Either next char or \0 */
91         }
92     }
93     
94     HeapFree(MSACM_hHeap, 0, pszBuffer);
95 }
96
97 /***********************************************************************
98  *           MSACM_UnregisterDriver32()
99  */
100 PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
101 {
102     PWINE_ACMDRIVERID pNextACMDriverID;
103     
104     while (p->pACMDriverList)
105         acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
106     
107     if (p->pszDriverAlias)
108         HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
109     if (p->pszFileName)
110         HeapFree(MSACM_hHeap, 0, p->pszFileName);
111     
112     if (p == MSACM_pFirstACMDriverID)
113         MSACM_pFirstACMDriverID = p->pNextACMDriverID;
114     if (p == MSACM_pLastACMDriverID)
115         MSACM_pLastACMDriverID = p->pPrevACMDriverID;
116
117     if (p->pPrevACMDriverID)
118         p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
119     if (p->pNextACMDriverID)
120         p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
121     
122     pNextACMDriverID = p->pNextACMDriverID;
123     
124     HeapFree(MSACM_hHeap, 0, p);
125     
126     return pNextACMDriverID;
127 }
128
129 /***********************************************************************
130  *           MSACM_UnregisterAllDrivers32()
131  * FIXME
132  *   Where should this function be called?
133  */
134 void MSACM_UnregisterAllDrivers(void)
135 {
136     PWINE_ACMDRIVERID p;
137
138     for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p));
139 }
140
141 /***********************************************************************
142  *           MSACM_GetDriverID32() 
143  */
144 PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
145 {
146     return (PWINE_ACMDRIVERID)hDriverID;
147 }
148
149 /***********************************************************************
150  *           MSACM_GetDriver32()
151  */
152 PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
153 {
154     return (PWINE_ACMDRIVER)hDriver;
155 }
156
157 /***********************************************************************
158  *           MSACM_GetObj32()
159  */
160 PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj)
161 {
162     return (PWINE_ACMOBJ)hObj;
163 }
164
165