DirectSound: correctly output device names as UTF-8 when compiled with UNICODE defined. Note that this patch may not be correct if UNICODE is not defined. Patch from Tobias Erichsen. See ticket #224 for details.

This commit is contained in:
rbencina 2014-04-11 05:44:50 +00:00
commit 666f30ea67

View file

@ -208,9 +208,9 @@ static signed long GetStreamWriteAvailable( PaStream* stream );
PaUtil_SetLastHostErrorInfo( paDirectSound, hr, "DirectSound error" ) PaUtil_SetLastHostErrorInfo( paDirectSound, hr, "DirectSound error" )
/************************************************* DX Prototypes **********/ /************************************************* DX Prototypes **********/
static BOOL CALLBACK CollectGUIDsProcA(LPGUID lpGUID, static BOOL CALLBACK CollectGUIDsProcW(LPGUID lpGUID,
LPCSTR lpszDesc, LPCWSTR lpszDesc,
LPCSTR lpszDrvName, LPCWSTR lpszDrvName,
LPVOID lpContext ); LPVOID lpContext );
/************************************************************************************/ /************************************************************************************/
@ -385,20 +385,35 @@ static double PaWinDs_GetMinLatencySeconds( double sampleRate )
/************************************************************************************ /************************************************************************************
** Duplicate the input string using the allocations allocator. ** Duplicate and convert the input string using the group allocations allocator.
** A NULL string is converted to a zero length string. ** A NULL string is converted to a zero length string.
** If memory cannot be allocated, NULL is returned. ** If memory cannot be allocated, NULL is returned.
**/ **/
static char *DuplicateDeviceNameString( PaUtilAllocationGroup *allocations, const char* src ) static char *DuplicateDeviceNameString( PaUtilAllocationGroup *allocations, const wchar_t* src )
{ {
char *result = 0; char *result = 0;
if( src != NULL ) if( src != NULL )
{ {
size_t len = strlen(src); #if !defined(_UNICODE) && !defined(UNICODE)
size_t len = WideCharToMultiByte(CP_ACP, 0, src, -1, NULL, 0, NULL, NULL);
result = (char*)PaUtil_GroupAllocateMemory( allocations, (long)(len + 1) );
if( result ) {
if (WideCharToMultiByte(CP_ACP, 0, src, -1, result, (int)len, NULL, NULL) == 0) {
result = 0;
}
}
#else
size_t len = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL);
result = (char*)PaUtil_GroupAllocateMemory( allocations, (long)(len + 1) ); result = (char*)PaUtil_GroupAllocateMemory( allocations, (long)(len + 1) );
if( result ) if( result ) {
memcpy( (void *) result, src, len+1 ); if (WideCharToMultiByte(CP_UTF8, 0, src, -1, result, (int)len, NULL, NULL) == 0) {
result = 0;
}
}
#endif
} }
else else
{ {
@ -513,9 +528,9 @@ static PaError TerminateDSDeviceNameAndGUIDVector( DSDeviceNameAndGUIDVector *gu
/************************************************************************************ /************************************************************************************
** Collect preliminary device information during DirectSound enumeration ** Collect preliminary device information during DirectSound enumeration
*/ */
static BOOL CALLBACK CollectGUIDsProcA(LPGUID lpGUID, static BOOL CALLBACK CollectGUIDsProcW(LPGUID lpGUID,
LPCSTR lpszDesc, LPCWSTR lpszDesc,
LPCSTR lpszDrvName, LPCWSTR lpszDrvName,
LPVOID lpContext ) LPVOID lpContext )
{ {
DSDeviceNameAndGUIDVector *namesAndGUIDs = (DSDeviceNameAndGUIDVector*)lpContext; DSDeviceNameAndGUIDVector *namesAndGUIDs = (DSDeviceNameAndGUIDVector*)lpContext;
@ -1211,9 +1226,9 @@ PaError PaWinDs_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInde
if( result != paNoError ) if( result != paNoError )
goto error; goto error;
paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateA( (LPDSENUMCALLBACKA)CollectGUIDsProcA, (void *)&deviceNamesAndGUIDs.inputNamesAndGUIDs ); paWinDsDSoundEntryPoints.DirectSoundCaptureEnumerateW( (LPDSENUMCALLBACKW)CollectGUIDsProcW, (void *)&deviceNamesAndGUIDs.inputNamesAndGUIDs );
paWinDsDSoundEntryPoints.DirectSoundEnumerateA( (LPDSENUMCALLBACKA)CollectGUIDsProcA, (void *)&deviceNamesAndGUIDs.outputNamesAndGUIDs ); paWinDsDSoundEntryPoints.DirectSoundEnumerateW( (LPDSENUMCALLBACKW)CollectGUIDsProcW, (void *)&deviceNamesAndGUIDs.outputNamesAndGUIDs );
if( deviceNamesAndGUIDs.inputNamesAndGUIDs.enumerationError != paNoError ) if( deviceNamesAndGUIDs.inputNamesAndGUIDs.enumerationError != paNoError )
{ {