From 17b895bb8f4c103d88bde3defd5124cbb164db6e Mon Sep 17 00:00:00 2001 From: petris Date: Tue, 22 Dec 2020 18:30:19 +0100 Subject: [PATCH] Fix ANSI in MME and DSound --- src/hostapi/dsound/pa_win_ds.c | 11 ------ src/hostapi/wmme/pa_win_wmme.c | 70 ++++++++++------------------------ 2 files changed, 21 insertions(+), 60 deletions(-) diff --git a/src/hostapi/dsound/pa_win_ds.c b/src/hostapi/dsound/pa_win_ds.c index f3cb67f..f2dcf90 100644 --- a/src/hostapi/dsound/pa_win_ds.c +++ b/src/hostapi/dsound/pa_win_ds.c @@ -408,16 +408,6 @@ static char *DuplicateDeviceNameString( PaUtilAllocationGroup *allocations, cons if( src != NULL ) { -#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) ); @@ -426,7 +416,6 @@ static char *DuplicateDeviceNameString( PaUtilAllocationGroup *allocations, cons result = 0; } } -#endif } else { diff --git a/src/hostapi/wmme/pa_win_wmme.c b/src/hostapi/wmme/pa_win_wmme.c index b62693b..bf48be5 100644 --- a/src/hostapi/wmme/pa_win_wmme.c +++ b/src/hostapi/wmme/pa_win_wmme.c @@ -204,12 +204,9 @@ static const char constOutputMapperSuffix_[] = " - Output"; /********************************************************************/ -/* Copy null-terminated TCHAR string to explicit char string using UTF8 encoding */ -static char *CopyTCharStringToUtf8CString(char *destination, size_t destLengthBytes, const TCHAR *source) +/* Copy null-terminated WCHAR string to explicit char string using UTF8 encoding */ +static char *CopyWCharStringToUtf8CString(char *destination, size_t destLengthBytes, const WCHAR *source) { -#if !defined(_UNICODE) && !defined(UNICODE) - return strcpy(destination, source); -#else /* The cbMultiByte parameter ["destLengthBytes" below] is: """ Size, in bytes, of the buffer indicated by lpMultiByteStr ["destination" below]. @@ -237,18 +234,13 @@ static char *CopyTCharStringToUtf8CString(char *destination, size_t destLengthBy if (WideCharToMultiByte(CP_UTF8, 0, source, -1, destination, /*cbMultiByte=*/intDestLengthBytes, NULL, NULL) == 0) return NULL; return destination; -#endif } /* returns required length (in bytes) of destination buffer when - converting TCHAR string to UTF8 bytes, not including the terminating null. */ -static size_t TCharStringLen(const TCHAR *str) + converting WCHAR string to UTF8 bytes, not including the terminating null. */ +static size_t WCharStringLen(const WCHAR *str) { -#if !defined(_UNICODE) && !defined(UNICODE) - return strlen(str); -#else - return WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); -#endif + return WideCharToMultiByte(CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL); } /********************************************************************/ @@ -298,14 +290,12 @@ static signed long GetStreamWriteAvailable( PaStream* stream ); /* macros for setting last host error information */ -#ifdef UNICODE - #define PA_MME_SET_LAST_WAVEIN_ERROR( mmresult ) \ { \ wchar_t mmeErrorTextWide[ MAXERRORLENGTH ]; \ char mmeErrorText[ MAXERRORLENGTH ]; \ - waveInGetErrorText( mmresult, mmeErrorTextWide, MAXERRORLENGTH ); \ - WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ + waveInGetErrorTextW( mmresult, mmeErrorTextWide, MAXERRORLENGTH ); \ + WideCharToMultiByte( CP_UTF8, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ mmeErrorTextWide, -1, mmeErrorText, MAXERRORLENGTH, NULL, NULL ); \ PaUtil_SetLastHostErrorInfo( paMME, mmresult, mmeErrorText ); \ } @@ -314,29 +304,11 @@ static signed long GetStreamWriteAvailable( PaStream* stream ); { \ wchar_t mmeErrorTextWide[ MAXERRORLENGTH ]; \ char mmeErrorText[ MAXERRORLENGTH ]; \ - waveOutGetErrorText( mmresult, mmeErrorTextWide, MAXERRORLENGTH ); \ - WideCharToMultiByte( CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ + waveOutGetErrorTextW( mmresult, mmeErrorTextWide, MAXERRORLENGTH ); \ + WideCharToMultiByte( CP_UTF8, WC_COMPOSITECHECK | WC_DEFAULTCHAR,\ mmeErrorTextWide, -1, mmeErrorText, MAXERRORLENGTH, NULL, NULL ); \ PaUtil_SetLastHostErrorInfo( paMME, mmresult, mmeErrorText ); \ } - -#else /* !UNICODE */ - -#define PA_MME_SET_LAST_WAVEIN_ERROR( mmresult ) \ - { \ - char mmeErrorText[ MAXERRORLENGTH ]; \ - waveInGetErrorText( mmresult, mmeErrorText, MAXERRORLENGTH ); \ - PaUtil_SetLastHostErrorInfo( paMME, mmresult, mmeErrorText ); \ - } - -#define PA_MME_SET_LAST_WAVEOUT_ERROR( mmresult ) \ - { \ - char mmeErrorText[ MAXERRORLENGTH ]; \ - waveOutGetErrorText( mmresult, mmeErrorText, MAXERRORLENGTH ); \ - PaUtil_SetLastHostErrorInfo( paMME, mmresult, mmeErrorText ); \ - } - -#endif /* UNICODE */ static void PaMme_SetLastSystemError( DWORD errorCode ) @@ -709,13 +681,13 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH PaError result = paNoError; char *deviceName; /* non-const ptr */ MMRESULT mmresult; - WAVEINCAPS wic; + WAVEINCAPSW wic; PaDeviceInfo *deviceInfo = &winMmeDeviceInfo->inheritedDeviceInfo; size_t len; *success = 0; - mmresult = waveInGetDevCaps( winMmeInputDeviceId, &wic, sizeof( WAVEINCAPS ) ); + mmresult = waveInGetDevCapsW( winMmeInputDeviceId, &wic, sizeof( WAVEINCAPSW ) ); if( mmresult == MMSYSERR_NOMEM ) { result = paInsufficientMemory; @@ -735,7 +707,7 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH so we are limited to displaying only the first 31 characters of the device name. */ if( winMmeInputDeviceId == WAVE_MAPPER ) { - len = TCharStringLen( wic.szPname ) + 1 + sizeof(constInputMapperSuffix_); + len = WCharStringLen( wic.szPname ) + 1 + sizeof(constInputMapperSuffix_); /* Append I/O suffix to WAVE_MAPPER device. */ deviceName = (char*)PaUtil_GroupAllocateMemory( winMmeHostApi->allocations, @@ -745,12 +717,12 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH result = paInsufficientMemory; goto error; } - CopyTCharStringToUtf8CString( deviceName, len, wic.szPname ); + CopyWCharStringToUtf8CString( deviceName, len, wic.szPname ); strcat( deviceName, constInputMapperSuffix_ ); } else { - len = TCharStringLen( wic.szPname ) + 1; + len = WCharStringLen( wic.szPname ) + 1; deviceName = (char*)PaUtil_GroupAllocateMemory( winMmeHostApi->allocations, (long)len ); @@ -759,7 +731,7 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH result = paInsufficientMemory; goto error; } - CopyTCharStringToUtf8CString( deviceName, len, wic.szPname ); + CopyWCharStringToUtf8CString( deviceName, len, wic.szPname ); } deviceInfo->name = deviceName; @@ -842,7 +814,7 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme PaError result = paNoError; char *deviceName; /* non-const ptr */ MMRESULT mmresult; - WAVEOUTCAPS woc; + WAVEOUTCAPSW woc; PaDeviceInfo *deviceInfo = &winMmeDeviceInfo->inheritedDeviceInfo; size_t len; #ifdef PAWIN_USE_WDMKS_DEVICE_INFO @@ -851,7 +823,7 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme *success = 0; - mmresult = waveOutGetDevCaps( winMmeOutputDeviceId, &woc, sizeof( WAVEOUTCAPS ) ); + mmresult = waveOutGetDevCapsW( winMmeOutputDeviceId, &woc, sizeof( WAVEOUTCAPSW ) ); if( mmresult == MMSYSERR_NOMEM ) { result = paInsufficientMemory; @@ -872,7 +844,7 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme if( winMmeOutputDeviceId == WAVE_MAPPER ) { /* Append I/O suffix to WAVE_MAPPER device. */ - len = TCharStringLen( woc.szPname ) + 1 + sizeof(constOutputMapperSuffix_); + len = WCharStringLen( woc.szPname ) + 1 + sizeof(constOutputMapperSuffix_); deviceName = (char*)PaUtil_GroupAllocateMemory( winMmeHostApi->allocations, (long)len ); @@ -881,12 +853,12 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme result = paInsufficientMemory; goto error; } - CopyTCharStringToUtf8CString( deviceName, len, woc.szPname ); + CopyWCharStringToUtf8CString( deviceName, len, woc.szPname ); strcat( deviceName, constOutputMapperSuffix_ ); } else { - len = TCharStringLen( woc.szPname ) + 1; + len = WCharStringLen( woc.szPname ) + 1; deviceName = (char*)PaUtil_GroupAllocateMemory( winMmeHostApi->allocations, (long)len ); @@ -895,7 +867,7 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme result = paInsufficientMemory; goto error; } - CopyTCharStringToUtf8CString( deviceName, len, woc.szPname ); + CopyWCharStringToUtf8CString( deviceName, len, woc.szPname ); } deviceInfo->name = deviceName; -- 2.43.0