From 8617c00d6feacdeba61bc09045cc05cbcc096479 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 31 Jul 2011 18:24:15 -0700 Subject: [PATCH] Wrap the wide-char enumerating functions instead of the ASCII OpenAL gives ASCII strings, so it's wasteful to convert to WCHAR when it's just going to be converted right back to ASCII. --- dsound_main.c | 139 +++++++++++++++++++++++++--------------------------------- 1 file changed, 59 insertions(+), 80 deletions(-) diff --git a/dsound_main.c b/dsound_main.c index 2f438f9..0007baf 100644 --- a/dsound_main.c +++ b/dsound_main.c @@ -462,19 +462,19 @@ HRESULT WINAPI GetDeviceID(LPCGUID pGuidSrc, LPGUID pGuidDest) struct morecontext { - LPDSENUMCALLBACKA callA; + LPDSENUMCALLBACKW callW; LPVOID data; }; -static BOOL CALLBACK a_to_w_callback(LPGUID guid, LPCWSTR descW, LPCWSTR modW, LPVOID data) +static BOOL CALLBACK w_to_a_callback(LPGUID guid, LPCSTR descA, LPCSTR modA, LPVOID data) { struct morecontext *context = data; - char descA[MAXPNAMELEN], modA[MAXPNAMELEN]; + WCHAR descW[MAXPNAMELEN], modW[MAXPNAMELEN]; - WideCharToMultiByte(CP_ACP, 0, descW, -1, descA, sizeof(descA), NULL, NULL); - WideCharToMultiByte(CP_ACP, 0, modW, -1, modA, sizeof(modA), NULL, NULL); + MultiByteToWideChar(CP_ACP, 0, descA, -1, descW, sizeof(descW)/sizeof(descW[0])); + MultiByteToWideChar(CP_ACP, 0, modA, -1, modW, sizeof(modW)/sizeof(modW[0])); - return context->callA(guid, descA, modA, context->data); + return context->callW(guid, descW, modW, context->data); } /*************************************************************************** @@ -494,36 +494,6 @@ HRESULT WINAPI DirectSoundEnumerateA( LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext) { - struct morecontext context; - - if (lpDSEnumCallback == NULL) { - WARN("invalid parameter: lpDSEnumCallback == NULL\n"); - return DSERR_INVALIDPARAM; - } - - context.callA = lpDSEnumCallback; - context.data = lpContext; - - return DirectSoundEnumerateW(a_to_w_callback, &context); -} - -/*************************************************************************** - * DirectSoundEnumerateW [DSOUND.3] - * - * Enumerate all DirectSound drivers installed in the system - * - * PARAMS - * lpDSEnumCallback [I] Address of callback function. - * lpContext [I] Address of user defined context passed to callback function. - * - * RETURNS - * Success: DS_OK - * Failure: DSERR_INVALIDPARAM - */ -HRESULT WINAPI DirectSoundEnumerateW( - LPDSENUMCALLBACKW lpDSEnumCallback, - LPVOID lpContext ) -{ TRACE("lpDSEnumCallback = %p, lpContext = %p\n", lpDSEnumCallback, lpContext); @@ -533,38 +503,28 @@ HRESULT WINAPI DirectSoundEnumerateW( } else if (openal_loaded) { - GUID guid; - WCHAR wDesc[MAXPNAMELEN]; - WCHAR wName[MAXPNAMELEN]; const ALCchar *devstr; - static const WCHAR empty[] = { 0 }; + GUID guid; + EnterCriticalSection(&openal_crst); devstr = DSOUND_getdevicestrings(); - if (!devstr || !*devstr) + if(!devstr || !*devstr) goto out; TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n", "Primary Sound Driver","",lpContext); - MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1, - wDesc, sizeof(wDesc)/sizeof(WCHAR) ); - if (lpDSEnumCallback(NULL, wDesc, empty, lpContext) == FALSE) + if(lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE) goto out; guid = DSOUND_renderer_guid; do { TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n", debugstr_guid(&guid),devstr,"wineal.drv",lpContext); - MultiByteToWideChar( CP_UNIXCP, 0, devstr, -1, - wDesc, sizeof(wDesc)/sizeof(WCHAR)-1 ); - wDesc[sizeof(wDesc)/sizeof(WCHAR)-1] = 0; - MultiByteToWideChar( CP_ACP, 0, "wineal.drv", -1, - wName, sizeof(wName)/sizeof(WCHAR)-1 ); - if (lpDSEnumCallback(&guid, wDesc, wName, lpContext) == FALSE) + if(lpDSEnumCallback(&guid, devstr, "wineal.drv", lpContext) == FALSE) goto out; guid.Data4[7]++; devstr += strlen(devstr)+1; - } while (*devstr); - + } while(*devstr); out: LeaveCriticalSection(&openal_crst); } @@ -577,9 +537,9 @@ out: } /*************************************************************************** - * DirectSoundCaptureEnumerateA [DSOUND.7] + * DirectSoundEnumerateW [DSOUND.3] * - * Enumerate all DirectSound drivers installed in the system. + * Enumerate all DirectSound drivers installed in the system * * PARAMS * lpDSEnumCallback [I] Address of callback function. @@ -589,25 +549,25 @@ out: * Success: DS_OK * Failure: DSERR_INVALIDPARAM */ -HRESULT WINAPI DirectSoundCaptureEnumerateA( - LPDSENUMCALLBACKA lpDSEnumCallback, - LPVOID lpContext) +HRESULT WINAPI DirectSoundEnumerateW( + LPDSENUMCALLBACKW lpDSEnumCallback, + LPVOID lpContext ) { struct morecontext context; - if (lpDSEnumCallback == NULL) { + if(lpDSEnumCallback == NULL) { WARN("invalid parameter: lpDSEnumCallback == NULL\n"); return DSERR_INVALIDPARAM; } - context.callA = lpDSEnumCallback; + context.callW = lpDSEnumCallback; context.data = lpContext; - return DirectSoundCaptureEnumerateW(a_to_w_callback, &context); + return DirectSoundEnumerateA(w_to_a_callback, &context); } /*************************************************************************** - * DirectSoundCaptureEnumerateW [DSOUND.8] + * DirectSoundCaptureEnumerateA [DSOUND.7] * * Enumerate all DirectSound drivers installed in the system. * @@ -619,9 +579,8 @@ HRESULT WINAPI DirectSoundCaptureEnumerateA( * Success: DS_OK * Failure: DSERR_INVALIDPARAM */ -HRESULT WINAPI -DirectSoundCaptureEnumerateW( - LPDSENUMCALLBACKW lpDSEnumCallback, +HRESULT WINAPI DirectSoundCaptureEnumerateA( + LPDSENUMCALLBACKA lpDSEnumCallback, LPVOID lpContext) { TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext ); @@ -632,39 +591,28 @@ DirectSoundCaptureEnumerateW( } else if (openal_loaded) { - GUID guid; - WCHAR wDesc[MAXPNAMELEN]; - WCHAR wName[MAXPNAMELEN]; const ALCchar *devstr; - static const WCHAR empty[] = { 0 }; + GUID guid; EnterCriticalSection(&openal_crst); devstr = DSOUND_getcapturedevicestrings(); - if (!devstr || !*devstr) + if(!devstr || !*devstr) goto out; TRACE("calling lpDSEnumCallback(NULL,\"%s\",\"%s\",%p)\n", "Primary Sound Capture Driver","",lpContext); - MultiByteToWideChar( CP_ACP, 0, "Primary Sound Driver", -1, - wDesc, sizeof(wDesc)/sizeof(WCHAR) ); - if (lpDSEnumCallback(NULL, wDesc, empty, lpContext) == FALSE) + if(lpDSEnumCallback(NULL, "Primary Sound Driver", "", lpContext) == FALSE) goto out; guid = DSOUND_capture_guid; do { TRACE("calling lpDSEnumCallback(%s,\"%s\",\"%s\",%p)\n", debugstr_guid(&guid),devstr,"wineal.drv",lpContext); - MultiByteToWideChar( CP_UNIXCP, 0, devstr, -1, - wDesc, sizeof(wDesc)/sizeof(WCHAR)-1 ); - wDesc[sizeof(wDesc)/sizeof(WCHAR)-1] = 0; - MultiByteToWideChar( CP_ACP, 0, "wineal.drv", -1, - wName, sizeof(wName)/sizeof(WCHAR)-1 ); - if (lpDSEnumCallback(&guid, wDesc, wName, lpContext) == FALSE) + if(lpDSEnumCallback(&guid, devstr, "wineal.drv", lpContext) == FALSE) goto out; guid.Data4[7]++; devstr += strlen(devstr)+1; - } while (*devstr); - + } while(*devstr); out: LeaveCriticalSection(&openal_crst); } @@ -676,6 +624,37 @@ out: return DS_OK; } +/*************************************************************************** + * DirectSoundCaptureEnumerateW [DSOUND.8] + * + * Enumerate all DirectSound drivers installed in the system. + * + * PARAMS + * lpDSEnumCallback [I] Address of callback function. + * lpContext [I] Address of user defined context passed to callback function. + * + * RETURNS + * Success: DS_OK + * Failure: DSERR_INVALIDPARAM + */ +HRESULT WINAPI +DirectSoundCaptureEnumerateW( + LPDSENUMCALLBACKW lpDSEnumCallback, + LPVOID lpContext) +{ + struct morecontext context; + + if (lpDSEnumCallback == NULL) { + WARN("invalid parameter: lpDSEnumCallback == NULL\n"); + return DSERR_INVALIDPARAM; + } + + context.callW = lpDSEnumCallback; + context.data = lpContext; + + return DirectSoundCaptureEnumerateA(w_to_a_callback, &context); +} + /******************************************************************************* * DirectSoundCreate (DSOUND.1) * -- 2.11.4.GIT