| 1 | /* $Id: internal.cpp,v 1.6 2000-11-19 13:08:42 sandervl Exp $ */ | 
|---|
| 2 | /* -*- tab-width: 8; c-basic-offset: 4 -*- */ | 
|---|
| 3 |  | 
|---|
| 4 | /* | 
|---|
| 5 | *      MSACM32 library | 
|---|
| 6 | * | 
|---|
| 7 | *      Copyright 1998  Patrik Stridvall | 
|---|
| 8 | *                1999  Eric Pouech | 
|---|
| 9 | */ | 
|---|
| 10 |  | 
|---|
| 11 | #include <os2win.h> | 
|---|
| 12 | #include <string.h> | 
|---|
| 13 |  | 
|---|
| 14 | #include "winbase.h" | 
|---|
| 15 | #include "winuser.h" | 
|---|
| 16 | #include "winerror.h" | 
|---|
| 17 | ////#include "driver.h" | 
|---|
| 18 | #include "heapstring.h" | 
|---|
| 19 | #include "mmsystem.h" | 
|---|
| 20 | #include "msacm.h" | 
|---|
| 21 | #include "msacmdrv.h" | 
|---|
| 22 | #include "wineacm.h" | 
|---|
| 23 | #include "debugtools.h" | 
|---|
| 24 |  | 
|---|
| 25 | DEFAULT_DEBUG_CHANNEL(msacm) | 
|---|
| 26 |  | 
|---|
| 27 | /**********************************************************************/ | 
|---|
| 28 |  | 
|---|
| 29 | HANDLE MSACM_hHeap = (HANDLE) NULL; | 
|---|
| 30 | PWINE_ACMDRIVERID MSACM_pFirstACMDriverID = NULL; | 
|---|
| 31 | PWINE_ACMDRIVERID MSACM_pLastACMDriverID = NULL; | 
|---|
| 32 |  | 
|---|
| 33 | /*********************************************************************** | 
|---|
| 34 | *           MSACM_RegisterDriver32() | 
|---|
| 35 | */ | 
|---|
| 36 | PWINE_ACMDRIVERID MSACM_RegisterDriver(LPSTR pszDriverAlias, LPSTR pszFileName, | 
|---|
| 37 | HINSTANCE hinstModule) | 
|---|
| 38 | { | 
|---|
| 39 | PWINE_ACMDRIVERID padid; | 
|---|
| 40 |  | 
|---|
| 41 | TRACE("('%s', '%s', 0x%08x)\n", pszDriverAlias, pszFileName, hinstModule); | 
|---|
| 42 |  | 
|---|
| 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; | 
|---|
| 56 |  | 
|---|
| 57 | return padid; | 
|---|
| 58 | } | 
|---|
| 59 |  | 
|---|
| 60 | /*********************************************************************** | 
|---|
| 61 | *           MSACM_RegisterAllDrivers32() | 
|---|
| 62 | */ | 
|---|
| 63 | void MSACM_RegisterAllDrivers(void) | 
|---|
| 64 | { | 
|---|
| 65 | LPSTR pszBuffer; | 
|---|
| 66 | DWORD dwBufferLength; | 
|---|
| 67 |  | 
|---|
| 68 | /* FIXME | 
|---|
| 69 | *  What if the user edits system.ini while the program is running? | 
|---|
| 70 | *  Does Windows handle that? | 
|---|
| 71 | */ | 
|---|
| 72 | if (MSACM_pFirstACMDriverID) | 
|---|
| 73 | return; | 
|---|
| 74 |  | 
|---|
| 75 | /* FIXME: Do not work! How do I determine the section length? */ | 
|---|
| 76 | dwBufferLength = 1024; | 
|---|
| 77 | /* EPP  GetPrivateProfileSectionA("drivers32", NULL, 0, "system.ini"); */ | 
|---|
| 78 |  | 
|---|
| 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); | 
|---|
| 89 | } | 
|---|
| 90 | } | 
|---|
| 91 | s += lstrlenA(s) + 1; /* Either next char or \0 */ | 
|---|
| 92 | } | 
|---|
| 93 | } | 
|---|
| 94 |  | 
|---|
| 95 | HeapFree(MSACM_hHeap, 0, pszBuffer); | 
|---|
| 96 | } | 
|---|
| 97 |  | 
|---|
| 98 | /*********************************************************************** | 
|---|
| 99 | *           MSACM_UnregisterDriver32() | 
|---|
| 100 | */ | 
|---|
| 101 | PWINE_ACMDRIVERID MSACM_UnregisterDriver(PWINE_ACMDRIVERID p) | 
|---|
| 102 | { | 
|---|
| 103 | PWINE_ACMDRIVERID pNextACMDriverID; | 
|---|
| 104 |  | 
|---|
| 105 | if (p->pACMDriverList) | 
|---|
| 106 | acmDriverClose((HACMDRIVER) p->pACMDriverList, 0); | 
|---|
| 107 |  | 
|---|
| 108 | if (p->pszDriverAlias) | 
|---|
| 109 | HeapFree(MSACM_hHeap, 0, p->pszDriverAlias); | 
|---|
| 110 | if (p->pszFileName) | 
|---|
| 111 | HeapFree(MSACM_hHeap, 0, p->pszFileName); | 
|---|
| 112 |  | 
|---|
| 113 | if (p == MSACM_pFirstACMDriverID) | 
|---|
| 114 | MSACM_pFirstACMDriverID = p->pNextACMDriverID; | 
|---|
| 115 | if (p == MSACM_pLastACMDriverID) | 
|---|
| 116 | MSACM_pLastACMDriverID = p->pPrevACMDriverID; | 
|---|
| 117 |  | 
|---|
| 118 | if (p->pPrevACMDriverID) | 
|---|
| 119 | p->pPrevACMDriverID->pNextACMDriverID = p->pNextACMDriverID; | 
|---|
| 120 | if (p->pNextACMDriverID) | 
|---|
| 121 | p->pNextACMDriverID->pPrevACMDriverID = p->pPrevACMDriverID; | 
|---|
| 122 |  | 
|---|
| 123 | pNextACMDriverID = p->pNextACMDriverID; | 
|---|
| 124 |  | 
|---|
| 125 | HeapFree(MSACM_hHeap, 0, p); | 
|---|
| 126 |  | 
|---|
| 127 | return pNextACMDriverID; | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 | /*********************************************************************** | 
|---|
| 131 | *           MSACM_UnregisterAllDrivers32() | 
|---|
| 132 | * FIXME | 
|---|
| 133 | *   Where should this function be called? | 
|---|
| 134 | */ | 
|---|
| 135 | void MSACM_UnregisterAllDrivers(void) | 
|---|
| 136 | { | 
|---|
| 137 | PWINE_ACMDRIVERID p; | 
|---|
| 138 |  | 
|---|
| 139 | for (p = MSACM_pFirstACMDriverID; p; p = MSACM_UnregisterDriver(p)); | 
|---|
| 140 | } | 
|---|
| 141 |  | 
|---|
| 142 | /*********************************************************************** | 
|---|
| 143 | *           MSACM_GetDriverID32() | 
|---|
| 144 | */ | 
|---|
| 145 | PWINE_ACMDRIVERID MSACM_GetDriverID(HACMDRIVERID hDriverID) | 
|---|
| 146 | { | 
|---|
| 147 | return (PWINE_ACMDRIVERID)hDriverID; | 
|---|
| 148 | } | 
|---|
| 149 |  | 
|---|
| 150 | /*********************************************************************** | 
|---|
| 151 | *           MSACM_GetDriver32() | 
|---|
| 152 | */ | 
|---|
| 153 | PWINE_ACMDRIVER MSACM_GetDriver(HACMDRIVER hDriver) | 
|---|
| 154 | { | 
|---|
| 155 | return (PWINE_ACMDRIVER)hDriver; | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | /*********************************************************************** | 
|---|
| 159 | *           MSACM_GetObj32() | 
|---|
| 160 | */ | 
|---|
| 161 | PWINE_ACMOBJ MSACM_GetObj(HACMOBJ hObj) | 
|---|
| 162 | { | 
|---|
| 163 | return (PWINE_ACMOBJ)hObj; | 
|---|
| 164 | } | 
|---|
| 165 |  | 
|---|
| 166 |  | 
|---|