source: trunk/src/msacm32/internal.c

Last change on this file was 6712, checked in by sandervl, 24 years ago

restored old version

File size: 5.4 KB
RevLine 
[5434]1/* -*- tab-width: 8; c-basic-offset: 4 -*- */
[6712]2
[5434]3/*
4 * MSACM32 library
5 *
6 * Copyright 1998 Patrik Stridvall
[6712]7 * 1999 Eric Pouech
[5434]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
27DEFAULT_DEBUG_CHANNEL(msacm);
28
29/**********************************************************************/
30
31HANDLE MSACM_hHeap = (HANDLE) NULL;
32PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL;
33PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL;
34
35/***********************************************************************
[6712]36 * MSACM_RegisterDriver()
[5434]37 */
38PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName,
[6712]39 HINSTANCE hinstModule)
40{
[5434]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)
[6712]66 MSACM_pLastACMDriverID->pNextACMDriverID = padid;
[5434]67 MSACM_pLastACMDriverID = padid;
68 if (!MSACM_pFirstACMDriverID)
[6712]69 MSACM_pFirstACMDriverID = padid;
70
[5434]71 return padid;
72}
73
74/***********************************************************************
[6712]75 * MSACM_RegisterAllDrivers()
[5434]76 */
77void MSACM_RegisterAllDrivers(void)
78{
79 LPSTR pszBuffer;
80 DWORD dwBufferLength;
81
[6712]82 /* FIXME
[5434]83 * What if the user edits system.ini while the program is running?
84 * Does Windows handle that?
85 */
86 if (MSACM_pFirstACMDriverID)
[6712]87 return;
88
[5434]89 /* FIXME: Do not work! How do I determine the section length? */
90 dwBufferLength = 1024;
[6712]91/* EPP GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */
92
[5434]93 pszBuffer = (LPSTR) HeapAlloc(MSACM_hHeap, 0, dwBufferLength);
94 if (GetPrivateProfileSectionA("drivers32", pszBuffer, dwBufferLength, "system.ini")) {
[6712]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 }
[5434]108 }
[6712]109
[5434]110 HeapFree(MSACM_hHeap, 0, pszBuffer);
111
112 MSACM_RegisterDriver("msacm32.dll", "msacm32.dll", 0);
113}
114
115/***********************************************************************
116 * MSACM_UnregisterDriver()
117 */
118PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p)
119{
120 PWINE_ACMDRIVERID pNextACMDriverID;
[6712]121
[5434]122 while (p->pACMDriverList)
[6712]123 acmDriverClose((HACMDRIVER) p->pACMDriverList, 0);
124
[5434]125 if (p->pszDriverAlias)
[6712]126 HeapFree(MSACM_hHeap, 0, p->pszDriverAlias);
[5434]127 if (p->pszFileName)
[6712]128 HeapFree(MSACM_hHeap, 0, p->pszFileName);
129
[5434]130 if (p == MSACM_pFirstACMDriverID)
[6712]131 MSACM_pFirstACMDriverID = p->pNextACMDriverID;
[5434]132 if (p == MSACM_pLastACMDriverID)
[6712]133 MSACM_pLastACMDriverID = p->pPrevACMDriverID;
[5434]134
135 if (p->pPrevACMDriverID)
[6712]136 p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID;
[5434]137 if (p->pNextACMDriverID)
[6712]138 p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID;
139
[5434]140 pNextACMDriverID = p->pNextACMDriverID;
[6712]141
[5434]142 HeapFree(MSACM_hHeap, 0, p);
[6712]143
[5434]144 return pNextACMDriverID;
145}
146
147/***********************************************************************
148 * MSACM_UnregisterAllDrivers()
149 * FIXME
150 * Where should this function be called?
151 */
152void 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 */
162PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj, DWORD type)
163{
[6712]164 PWINE_ACMOBJ pao = (PWINE_ACMOBJ)hObj;
[5434]165
166 if (pao == NULL || IsBadReadPtr(pao, sizeof(WINE_ACMOBJ)) ||
[6712]167 ((type != WINE_ACMOBJ_DONTCARE) && (type != pao->dwType)))
168 return NULL;
[5434]169 return pao;
170}
171
172/***********************************************************************
[6712]173 * MSACM_GetDriverID()
[5434]174 */
175PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID)
176{
177 return (PWINE_ACMDRIVERID)MSACM_GetObj((HACMOBJ)hDriverID, WINE_ACMOBJ_DRIVERID);
178}
179
180/***********************************************************************
181 * MSACM_GetDriver()
182 */
183PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver)
184{
185 return (PWINE_ACMDRIVER)MSACM_GetObj((HACMOBJ)hDriver, WINE_ACMOBJ_DRIVER);
186}
187
188/***********************************************************************
189 * MSACM_Message()
190 */
191MMRESULT MSACM_Message(HACMDRIVER had, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
192{
[6712]193 PWINE_ACMDRIVER pad = MSACM_GetDriver(had);
[5434]194
195 return pad ? SendDriverMessage(pad->hDrvr, uMsg, lParam1, lParam2) : MMSYSERR_INVALHANDLE;
196}
Note: See TracBrowser for help on using the repository browser.