ReactOS 0.4.16-dev-88-ga65b6ae
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
12VOID
16 UINT ccount,
17 LPVOID DefaultString,
18 BOOL bUnicode)
19{
20 if (bUnicode)
21 {
22 /* load localized string */
24 {
25 /* default device name */
26 wcscpy((LPWSTR)Buffer, (LPWSTR)DefaultString);
27 }
28 }
29 else
30 {
31 /* load localized string */
33 {
34 /* default device name */
35 strcpy((LPSTR)Buffer, (LPSTR)DefaultString);
36 }
37 }
38}
39
40
41BOOL
43 LPDSENUMCALLBACKA lpDSEnumCallbackA,
44 LPDSENUMCALLBACKW lpDSEnumCallbackW,
45 LPGUID DeviceGuid,
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
107 LPDSENUMCALLBACKA lpDSEnumCallbackA,
108 LPDSENUMCALLBACKW lpDSEnumCallbackW,
109 LPVOID lpContext,
110 BOOL bPlayback)
111{
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 */
133 }
134 else
135 {
136 /* use resource id of playback string */
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
200WINAPI
202 LPDSENUMCALLBACKA lpDSEnumCallback,
203 LPVOID lpContext)
204{
205 return DSoundEnumerate(lpDSEnumCallback, NULL, lpContext, TRUE);
206}
207
209WINAPI
211 LPDSENUMCALLBACKW lpDSEnumCallback,
212 LPVOID lpContext )
213{
214 return DSoundEnumerate(NULL, lpDSEnumCallback, lpContext, TRUE);
215}
216
218WINAPI
220 LPDSENUMCALLBACKA lpDSEnumCallback,
221 LPVOID lpContext)
222{
223 return DSoundEnumerate(lpDSEnumCallback, NULL, lpContext, FALSE);
224}
225
227WINAPI
229 LPDSENUMCALLBACKW lpDSEnumCallback,
230 LPVOID lpContext)
231{
232 return DSoundEnumerate(NULL, lpDSEnumCallback, lpContext, FALSE);
233}
INT ResourceId
Definition: LoadImageGCC.c:72
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define LoadResourceString(hInst, uID)
Definition: utils.h:48
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT EnumAudioDeviceInterfaces(LPFILTERINFO *OutRootInfo)
Definition: devicelist.c:384
LPFILTERINFO RootInfo
Definition: dsound.c:13
HINSTANCE dsound_hInstance
Definition: dsound.c:12
HRESULT DSoundEnumerate(LPDSENUMCALLBACKA lpDSEnumCallbackA, LPDSENUMCALLBACKW lpDSEnumCallbackW, LPVOID lpContext, BOOL bPlayback)
Definition: enum.c:106
BOOL DoDSoundCallback(LPDSENUMCALLBACKA lpDSEnumCallbackA, LPDSENUMCALLBACKW lpDSEnumCallbackW, LPGUID DeviceGuid, UINT ResourceId, LPWSTR ProductName, LPWSTR DriverName, LPVOID lpContext)
Definition: enum.c:42
HRESULT WINAPI DirectSoundCaptureEnumerateA(LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:219
HRESULT WINAPI DirectSoundEnumerateW(LPDSENUMCALLBACKW lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:210
HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:201
HRESULT WINAPI DirectSoundCaptureEnumerateW(LPDSENUMCALLBACKW lpDSEnumCallback, LPVOID lpContext)
Definition: enum.c:228
#define IDS_PRIMARY_RECORD_DEVICE
Definition: resource.h:5
#define IDS_PRIMARY_PLAYBACK_DEVICE
Definition: resource.h:4
#define CP_ACP
Definition: compat.h:109
#define WideCharToMultiByte
Definition: compat.h:111
BOOL(CALLBACK * LPDSENUMCALLBACKW)(LPGUID, LPCWSTR, LPCWSTR, LPVOID)
Definition: dsound.h:404
#define DS_OK
Definition: dsound.h:116
#define DSERR_INVALIDPARAM
Definition: dsound.h:121
BOOL(CALLBACK * LPDSENUMCALLBACKA)(LPGUID, LPCSTR, LPCSTR, LPVOID)
Definition: dsound.h:405
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ULONG_MAX
Definition: limits.h:44
#define GUID_NULL
Definition: ks.h:106
#define MAXPNAMELEN
Definition: mmsystem.h:24
#define ASSERT(a)
Definition: mode.c:44
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define DPRINT
Definition: sndvol32.h:73
struct tagFILTERINFO * lpNext
Definition: precomp.h:48
GUID DeviceGuid[2]
Definition: precomp.h:45
ULONG MappedId[2]
Definition: precomp.h:46
WCHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1060
WCHAR szPname[MAXPNAMELEN]
Definition: mmsystem.h:1039
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
UINT WINAPI waveOutGetDevCapsW(UINT_PTR uDeviceID, LPWAVEOUTCAPSW lpCaps, UINT uSize)
Definition: winmm.c:2173
UINT WINAPI waveInGetDevCapsW(UINT_PTR uDeviceID, LPWAVEINCAPSW lpCaps, UINT uSize)
Definition: winmm.c:2573
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
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
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184