ReactOS  0.4.14-dev-608-gd495a4f
enum.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS Configuration of network devices
4  * FILE: dll/directx/dsound_new/enum.c
5  * PURPOSE: Handles DSound device enumeration
6  *
7  * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
8  */
9 
10 #include "precomp.h"
11 
12 VOID
14  UINT ResourceId,
15  LPVOID Buffer,
16  UINT ccount,
17  LPVOID DefaultString,
18  BOOL bUnicode)
19 {
20  if (bUnicode)
21  {
22  /* load localized string */
23  if (!LoadStringW(dsound_hInstance, ResourceId, (LPWSTR)Buffer, ccount))
24  {
25  /* default device name */
26  wcscpy((LPWSTR)Buffer, (LPWSTR)DefaultString);
27  }
28  }
29  else
30  {
31  /* load localized string */
32  if (!LoadStringA(dsound_hInstance, ResourceId, (LPSTR)Buffer, ccount))
33  {
34  /* default device name */
35  strcpy((LPSTR)Buffer, (LPSTR)DefaultString);
36  }
37  }
38 }
39 
40 
41 BOOL
43  LPDSENUMCALLBACKA lpDSEnumCallbackA,
44  LPDSENUMCALLBACKW lpDSEnumCallbackW,
45  LPGUID DeviceGuid,
46  UINT ResourceId,
47  LPWSTR ProductName,
48  LPWSTR DriverName,
49  LPVOID lpContext)
50 {
51  WCHAR Buffer[200] = {0};
52  char DriverNameA[200];
53 
54  static LPWSTR SoundDriverW = L"Primary Sound Driver";
55  static LPWSTR SoundDriverA = L"Primary Sound Driver";
56 
57  if (lpDSEnumCallbackW)
58  {
59  if (ResourceId)
60  {
61  /* load resource string */
62  Buffer[0] = 0;
63  LoadResourceString(ResourceId, (LPVOID)Buffer, sizeof(Buffer)/sizeof(WCHAR), (LPVOID)SoundDriverW, TRUE);
64  Buffer[(sizeof(Buffer)/sizeof(WCHAR))-1] = '\0';
65  }
66  else
67  {
68  /* use passed string */
69  ASSERT(ProductName);
70  wcscpy(Buffer, ProductName);
71  }
72 
73  /* perform callback */
74  return lpDSEnumCallbackW(DeviceGuid, Buffer, DriverName, lpContext);
75  }
76  else
77  {
78  if (ResourceId)
79  {
80  /* load resource string */
81  Buffer[0] = 0;
82  LoadResourceString(ResourceId, (LPVOID)Buffer, sizeof(Buffer)/sizeof(char), (LPVOID)SoundDriverA, FALSE);
83  Buffer[(sizeof(Buffer)/sizeof(WCHAR))-1] = 0;
84  }
85  else
86  {
87  /* use passed string */
88  Buffer[0] = 0;
89  WideCharToMultiByte(CP_ACP, 0, ProductName, -1, (LPSTR)Buffer, sizeof(Buffer) / sizeof(char), NULL, NULL);
90  Buffer[(sizeof(Buffer)/sizeof(WCHAR))-1] = 0;
91  }
92 
93  DriverNameA[0] = 0;
94  if (ProductName)
95  {
96  WideCharToMultiByte(CP_ACP, 0, ProductName, -1, DriverNameA, sizeof(DriverNameA) / sizeof(char), NULL, NULL);
97  DriverNameA[(sizeof(DriverNameA) / sizeof(char))-1] = 0;
98  }
99 
100  return lpDSEnumCallbackA(DeviceGuid, (LPSTR)Buffer, DriverNameA, lpContext);
101  }
102 }
103 
104 
105 HRESULT
107  LPDSENUMCALLBACKA lpDSEnumCallbackA,
108  LPDSENUMCALLBACKW lpDSEnumCallbackW,
109  LPVOID lpContext,
110  BOOL bPlayback)
111 {
112  ULONG ResourceId;
113  BOOL bResult;
114  LPFILTERINFO CurInfo;
115  WAVEOUTCAPSW WaveOutCaps;
116  WAVEINCAPSW WaveInCaps;
117 
118  if (!RootInfo)
119  {
121  }
122 
123  if (lpDSEnumCallbackA == NULL && lpDSEnumCallbackW == NULL)
124  {
125  DPRINT("No callback\n");
126  return DSERR_INVALIDPARAM;
127  }
128 
129  if (bPlayback)
130  {
131  /* use resource id of playback string */
132  ResourceId = IDS_PRIMARY_PLAYBACK_DEVICE;
133  }
134  else
135  {
136  /* use resource id of playback string */
137  ResourceId = IDS_PRIMARY_RECORD_DEVICE;
138  }
139 
140  if (RootInfo)
141  {
142  /* perform first callback */
143  bResult = DoDSoundCallback(lpDSEnumCallbackA, lpDSEnumCallbackW, NULL, ResourceId, NULL, L"", lpContext);
144  if (!bResult)
145  {
146  /* callback asked as to stop */
147  return DS_OK;
148  }
149 
150  /* now iterate through all devices */
151  CurInfo = RootInfo;
152 
153  do
154  {
155  if (bPlayback && !IsEqualGUID(&CurInfo->DeviceGuid[1], &GUID_NULL))
156  {
157  RtlZeroMemory(&WaveOutCaps, sizeof(WAVEOUTCAPSW));
158 
159  /* sanity check */
160  ASSERT(CurInfo->MappedId[1] != ULONG_MAX);
161 
162  /* get wave out caps */
163  waveOutGetDevCapsW((UINT_PTR)CurInfo->MappedId[1], &WaveOutCaps, sizeof(WAVEOUTCAPSW));
164  WaveOutCaps.szPname[MAXPNAMELEN-1] = L'\0';
165 
166  bResult = DoDSoundCallback(lpDSEnumCallbackA, lpDSEnumCallbackW, &CurInfo->DeviceGuid[1], 0, WaveOutCaps.szPname, L"" /* FIXME */, lpContext);
167  if (!bResult)
168  {
169  /* callback asked as to stop */
170  return DS_OK;
171  }
172  }
173  else if (!bPlayback && !IsEqualGUID(&CurInfo->DeviceGuid[0], &GUID_NULL))
174  {
175  RtlZeroMemory(&WaveInCaps, sizeof(WAVEINCAPSW));
176 
177  /* sanity check */
178  ASSERT(CurInfo->MappedId[1] != ULONG_MAX);
179 
180  /* get wave in caps */
181  waveInGetDevCapsW((UINT_PTR)CurInfo->MappedId[0], &WaveInCaps, sizeof(WAVEINCAPSW));
182  WaveInCaps.szPname[MAXPNAMELEN-1] = L'\0';
183 
184  bResult = DoDSoundCallback(lpDSEnumCallbackA, lpDSEnumCallbackW, &CurInfo->DeviceGuid[0], 0, WaveInCaps.szPname, L"" /* FIXME */, lpContext);
185  if (!bResult)
186  {
187  /* callback asked as to stop */
188  return DS_OK;
189  }
190  }
191 
192  /* move to next entry */
193  CurInfo = CurInfo->lpNext;
194  }while(CurInfo);
195  }
196  return DS_OK;
197 }
198 
199 HRESULT
200 WINAPI
202  LPDSENUMCALLBACKA lpDSEnumCallback,
203  LPVOID lpContext)
204 {
205  return DSoundEnumerate(lpDSEnumCallback, NULL, lpContext, TRUE);
206 }
207 
208 HRESULT
209 WINAPI
211  LPDSENUMCALLBACKW lpDSEnumCallback,
212  LPVOID lpContext )
213 {
214  return DSoundEnumerate(NULL, lpDSEnumCallback, lpContext, TRUE);
215 }
216 
217 HRESULT
218 WINAPI
220  LPDSENUMCALLBACKA lpDSEnumCallback,
221  LPVOID lpContext)
222 {
223  return DSoundEnumerate(lpDSEnumCallback, NULL, lpContext, FALSE);
224 }
225 
226 HRESULT
227 WINAPI
229  LPDSENUMCALLBACKW lpDSEnumCallback,
230  LPVOID lpContext)
231 {
232  return DSoundEnumerate(NULL, lpDSEnumCallback, lpContext, FALSE);
233 }
HRESULT EnumAudioDeviceInterfaces(LPFILTERINFO *OutRootInfo)
Definition: devicelist.c:384
#define TRUE
Definition: types.h:120
#define WideCharToMultiByte
Definition: compat.h:101
WCHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1060
struct tagFILTERINFO * lpNext
Definition: precomp.h:49
#define CP_ACP
Definition: compat.h:99
int WINAPI LoadStringA(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPSTR lpBuffer, _In_ int cchBufferMax)
char * LPSTR
Definition: xmlstorage.h:182
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
Definition: winmm.c:2576
UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps, UINT uSize)
Definition: winmm.c:2176
#define DSERR_INVALIDPARAM
Definition: dsound.h:121
unsigned int BOOL
Definition: ntddk_ex.h:94
HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:201
#define IDS_PRIMARY_RECORD_DEVICE
Definition: resource.h:5
HRESULT WINAPI DirectSoundCaptureEnumerateW(LPDSENUMCALLBACKW lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:228
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define IDS_PRIMARY_PLAYBACK_DEVICE
Definition: resource.h:4
HRESULT DSoundEnumerate(LPDSENUMCALLBACKA lpDSEnumCallbackA, LPDSENUMCALLBACKW lpDSEnumCallbackW, LPVOID lpContext, BOOL bPlayback)
Definition: enum.c:106
#define DS_OK
Definition: dsound.h:116
GUID DeviceGuid[2]
Definition: precomp.h:46
VOID LoadResourceString(UINT ResourceId, LPVOID Buffer, UINT ccount, LPVOID DefaultString, BOOL bUnicode)
Definition: enum.c:13
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:77
#define WINAPI
Definition: msvc.h:6
HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:210
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
WCHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1039
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define GUID_NULL
Definition: ks.h:106
LPFILTERINFO RootInfo
Definition: dsound.c:13
HINSTANCE dsound_hInstance
Definition: dsound.c:12
BOOL DoDSoundCallback(LPDSENUMCALLBACKA lpDSEnumCallbackA, LPDSENUMCALLBACKW lpDSEnumCallbackW, LPGUID DeviceGuid, UINT ResourceId, LPWSTR ProductName, LPWSTR DriverName, LPVOID lpContext)
Definition: enum.c:42
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
BOOL(CALLBACK * LPDSENUMCALLBACKA)(LPGUID, LPCSTR, LPCSTR, LPVOID)
Definition: dsound.h:405
#define MAXPNAMELEN
Definition: mmsystem.h:24
ULONG MappedId[2]
Definition: precomp.h:47
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
HRESULT WINAPI DirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:219
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
BOOL(CALLBACK * LPDSENUMCALLBACKW)(LPGUID, LPCWSTR, LPCWSTR, LPVOID)
Definition: dsound.h:404
#define ULONG_MAX
Definition: limits.h:44