ReactOS  0.4.15-dev-1207-g698a8e6
utils.c File Reference
#include "mmdrv.h"
#include <debug.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Classes

struct  _DEVICE_LIST
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _DEVICE_LIST DEVICE_LIST
 
typedef struct _DEVICE_LISTPDEVICE_LIST
 

Functions

DWORD TranslateStatus (void)
 
MMRESULT OpenDevice (UINT DeviceType, DWORD ID, PHANDLE pDeviceHandle, DWORD Access)
 
BOOL AddDeviceToList (PDEVICE_LIST *pList, DWORD DeviceType, DWORD CardIndex, LPWSTR Name)
 
VOID FreeDeviceList ()
 
MMRESULT FindDevices ()
 
DWORD GetDeviceCount (UINT DeviceType)
 

Variables

PDEVICE_LIST DeviceList
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file utils.c.

Typedef Documentation

◆ DEVICE_LIST

◆ PDEVICE_LIST

Function Documentation

◆ AddDeviceToList()

BOOL AddDeviceToList ( PDEVICE_LIST pList,
DWORD  DeviceType,
DWORD  CardIndex,
LPWSTR  Name 
)

Definition at line 111 of file utils.c.

113 {
114  PDEVICE_LIST pNewDevice;
115 
116  DPRINT("AddDeviceToList()\n");
117 
118  pNewDevice = (PDEVICE_LIST) HeapAlloc(Heap, 0,
119  sizeof(DEVICE_LIST) + lstrlen(Name) * sizeof(WCHAR));
120 
121  if ( !pNewDevice )
122  {
124  return FALSE;
125  }
126 
127  pNewDevice->DeviceType = DeviceType;
128  pNewDevice->CardIndex = CardIndex;
129  lstrcpy(pNewDevice->Name, Name);
130  pNewDevice->DeviceInstanceData = NULL;
131  pNewDevice->Next = *pList;
132  *pList = pNewDevice;
133 
134  DPRINT("Success!\n");
135 
136  return TRUE;
137 }
#define TRUE
Definition: types.h:120
DeviceType
Definition: mmdrv.h:41
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
ULONG CardIndex
Definition: utils.c:21
WCHAR Name[1]
Definition: utils.c:24
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _DEVICE_LIST * Next
Definition: utils.c:19
struct _DEVICE_LIST * PDEVICE_LIST
#define SetLastError(x)
Definition: compat.h:611
PVOID DeviceInstanceData
Definition: utils.c:22
#define lstrlen
Definition: winbase.h:3716
DWORD DeviceType
Definition: utils.c:20
#define lstrcpy
Definition: winbase.h:3714

Referenced by FindDevices().

◆ FindDevices()

MMRESULT FindDevices ( )

Definition at line 159 of file utils.c.

160 {
161 // DWORD Index;
162 // HKEY DriverKey;
163 
164  DPRINT("Finding devices\n");
165 
166 // DriverKey = OpenParametersKey();
167 // see drvutil.c of MS DDK for how this SHOULD be done...
168 
169 
170  SHORT i;
171  HANDLE h;
173 
175  {
176  wsprintf(DeviceName, L"WaveOut%d\0", i);
177  CloseHandle(h);
179  }
180 
182  {
183  wsprintf(DeviceName, L"WaveIn%d\0", i);
184  CloseHandle(h);
186  }
187 
189  {
190  wsprintf(DeviceName, L"MidiOut%d\0", i);
191  CloseHandle(h);
193  }
194 
196  {
197  wsprintf(DeviceName, L"MidiIn%d\0", i);
198  CloseHandle(h);
200  }
201 
202  for (i=0; OpenDevice(AuxDevice, i, &h, GENERIC_READ) == MMSYSERR_NOERROR; i++)
203  {
204  wsprintf(DeviceName, L"Aux%d\0", i);
205  CloseHandle(h);
207  }
208 
209 
210  // MIDI Out 0: MPU-401 UART
211  // AddDeviceToList(&DeviceList, MidiOutDevice, 0, L"MidiOut0");
212  // Wave Out 0: Sound Blaster 16 (ok?)
213  // AddDeviceToList(&DeviceList, WaveOutDevice, 0, L"WaveOut0");
214 
215  return MMSYSERR_NOERROR; // ok?
216 }
#define CloseHandle
Definition: compat.h:598
WCHAR DeviceName[]
Definition: adapter.cpp:21
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
short SHORT
Definition: pedump.c:59
void DPRINT(...)
Definition: polytest.cpp:61
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const WCHAR L[]
Definition: oid.c:1250
#define SOUND_MAX_DEVICE_NAME
Definition: mmdef.h:22
#define GENERIC_READ
Definition: compat.h:135
PDEVICE_LIST DeviceList
Definition: utils.c:27
MMRESULT OpenDevice(UINT DeviceType, DWORD ID, PHANDLE pDeviceHandle, DWORD Access)
Definition: utils.c:61
BOOL AddDeviceToList(PDEVICE_LIST *pList, DWORD DeviceType, DWORD CardIndex, LPWSTR Name)
Definition: utils.c:111
#define wsprintf
Definition: winuser.h:5840

Referenced by AtapiAdapterControl(), AtapiHwInitialize__(), and AtapiStartIo__().

◆ FreeDeviceList()

VOID FreeDeviceList ( )

Definition at line 140 of file utils.c.

141 {
142  PDEVICE_LIST pDevice;
143 
144  DPRINT("FreeDeviceList()\n");
145 
146  while (DeviceList)
147  {
148  pDevice = DeviceList;
149  DeviceList = pDevice->Next;
150 
151  if (pDevice->DeviceInstanceData)
152  HeapFree(Heap, 0, (LPVOID)pDevice->DeviceInstanceData);
153 
154  HeapFree(Heap, 0, (LPSTR)pDevice);
155  }
156 }
char * LPSTR
Definition: xmlstorage.h:182
void DPRINT(...)
Definition: polytest.cpp:61
struct _DEVICE_LIST * Next
Definition: utils.c:19
PVOID DeviceInstanceData
Definition: utils.c:22
PDEVICE_LIST DeviceList
Definition: utils.c:27
#define HeapFree(x, y, z)
Definition: compat.h:594

◆ GetDeviceCount()

DWORD GetDeviceCount ( UINT  DeviceType)

Definition at line 220 of file utils.c.

221 {
222  int i;
224 
225  for (List = DeviceList, i = 0; List != NULL; List = List->Next)
226  if (List->DeviceType == DeviceType)
227  i ++;
228 
229  return i;
230 }
DeviceType
Definition: mmdrv.h:41
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
LIST_ENTRY List
Definition: psmgr.c:57
PDEVICE_LIST DeviceList
Definition: utils.c:27

◆ OpenDevice()

MMRESULT OpenDevice ( UINT  DeviceType,
DWORD  ID,
PHANDLE  pDeviceHandle,
DWORD  Access 
)

Definition at line 61 of file utils.c.

63 {
64  DPRINT("OpenDevice()\n");
66  *pDeviceHandle = INVALID_HANDLE_VALUE;
67 
68  if (ID > SOUND_MAX_DEVICES)
69  return MMSYSERR_BADDEVICEID;
70 
71  switch(DeviceType)
72  {
73  case WaveOutDevice :
74  wsprintf(DeviceName, L"\\\\.%ls%d", WAVE_OUT_DEVICE_NAME_U + strlen("\\Device"), ID);
75  break;
76  case WaveInDevice :
77  wsprintf(DeviceName, L"\\\\.%ls%d", WAVE_IN_DEVICE_NAME_U + strlen("\\Device"), ID);
78  break;
79  case MidiOutDevice :
80  wsprintf(DeviceName, L"\\\\.%ls%d", MIDI_OUT_DEVICE_NAME_U + strlen("\\Device"), ID);
81  break;
82  case MidiInDevice :
83  wsprintf(DeviceName, L"\\\\.%ls%d", MIDI_IN_DEVICE_NAME_U + strlen("\\Device"), ID);
84  break;
85  case AuxDevice :
86  wsprintf(DeviceName, L"\\\\.%ls%d", AUX_DEVICE_NAME_U + strlen("\\Device"), ID);
87  break;
88  default :
89  DPRINT("No Auido Device Found");
90  return MMSYSERR_BADDEVICEID; /* Maybe we should change error code */
91  };
92 
93  DPRINT("Attempting to open %S\n", DeviceName);
94 
95  *pDeviceHandle = CreateFile(DeviceName, Access, FILE_SHARE_WRITE, NULL,
97  NULL);
98 
99  DPRINT("DeviceHandle == 0x%x\n", (int)*pDeviceHandle);
100 
101  if (pDeviceHandle == INVALID_HANDLE_VALUE)
102  return TranslateStatus();
103 
104  return MMSYSERR_NOERROR;
105 }
#define MIDI_OUT_DEVICE_NAME_U
Definition: mmdef.h:37
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
DeviceType
Definition: mmdrv.h:41
#define MIDI_IN_DEVICE_NAME_U
Definition: mmdef.h:35
#define WAVE_OUT_DEVICE_NAME_U
Definition: mmdef.h:32
#define WAVE_IN_DEVICE_NAME_U
Definition: mmdef.h:30
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
WCHAR DeviceName[]
Definition: adapter.cpp:21
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define AUX_DEVICE_NAME_U
Definition: mmdef.h:40
#define OPEN_EXISTING
Definition: compat.h:634
DWORD TranslateStatus(void)
Definition: utils.c:30
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SOUND_MAX_DEVICES
Definition: mmdef.h:23
static const WCHAR L[]
Definition: oid.c:1250
#define SOUND_MAX_DEVICE_NAME
Definition: mmdef.h:22
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
#define GENERIC_READ
Definition: compat.h:135
#define ID
Definition: ruserpass.c:36
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define wsprintf
Definition: winuser.h:5840

Referenced by FindDevices().

◆ TranslateStatus()

DWORD TranslateStatus ( void  )

Definition at line 30 of file utils.c.

31 {
32  switch(GetLastError())
33  {
34  case NO_ERROR :
35  case ERROR_IO_PENDING :
36  return MMSYSERR_NOERROR;
37 
38  case ERROR_BUSY :
39  return MMSYSERR_ALLOCATED;
40 
41  case ERROR_NOT_SUPPORTED :
43  return MMSYSERR_NOTSUPPORTED;
44 
46  return MMSYSERR_NOMEM;
47 
48  case ERROR_ACCESS_DENIED :
49  return MMSYSERR_BADDEVICEID;
50 
52  return MMSYSERR_INVALPARAM;
53 
54  default :
55  return MMSYSERR_ERROR;
56  };
57 }
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_BUSY
Definition: dderror.h:12
#define MMSYSERR_NOMEM
Definition: mmsystem.h:103
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define MMSYSERR_ERROR
Definition: mmsystem.h:97
#define MMSYSERR_ALLOCATED
Definition: mmsystem.h:100
#define MMSYSERR_NOTSUPPORTED
Definition: mmsystem.h:104
#define MMSYSERR_BADDEVICEID
Definition: mmsystem.h:98
#define MMSYSERR_INVALPARAM
Definition: mmsystem.h:107
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by AuxGetAudio(), AuxSetAudio(), OpenDevice(), and WriteMidi().

Variable Documentation

◆ DeviceList