From: rossb Date: Tue, 8 Dec 2009 09:26:33 +0000 (+0000) Subject: Patch from Dmitry Kostjuchenko: Fixes x64 issue with mis-casting DWORD_PTRs to DWORDs... X-Git-Tag: pa_stable_v19_20110326_r1647~199 X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=bdc279551c5482ff3e647eee5f86fb2d489718b1;p=portaudio Patch from Dmitry Kostjuchenko: Fixes x64 issue with mis-casting DWORD_PTRs to DWORDs, support proper conversion of device names in UNICODE builds, use of CreateThread instead of _beginthreadex with cygwin. --- diff --git a/src/hostapi/wmme/pa_win_wmme.c b/src/hostapi/wmme/pa_win_wmme.c index 06c525b..bb83686 100644 --- a/src/hostapi/wmme/pa_win_wmme.c +++ b/src/hostapi/wmme/pa_win_wmme.c @@ -152,13 +152,16 @@ Non-critical stuff for the future: #endif /* PAWIN_USE_WDMKS_DEVICE_INFO */ /* use CreateThread for CYGWIN, _beginthreadex for all others */ -#ifndef __CYGWIN__ +#if !defined(__CYGWIN__) && !defined(_WIN32_WCE) #define CREATE_THREAD (HANDLE)_beginthreadex( 0, 0, ProcessingThreadProc, stream, 0, &stream->processingThreadId ) +#define PA_THREAD_FUNC static unsigned WINAPI +#define PA_THREAD_ID unsigned #else #define CREATE_THREAD CreateThread( 0, 0, ProcessingThreadProc, stream, 0, &stream->processingThreadId ) +#define PA_THREAD_FUNC static DWORD WINAPI +#define PA_THREAD_ID DWORD #endif - -#if (defined(UNDER_CE)) +#if (defined(_WIN32_WCE)) #pragma comment(lib, "Coredll.lib") #elif (defined(WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1200))) /* MSC version 6 and above */ #pragma comment(lib, "winmm.lib") @@ -168,7 +171,11 @@ Non-critical stuff for the future: provided in newer platform sdks */ #ifndef DWORD_PTR -#define DWORD_PTR DWORD + #if defined(_WIN64) + #define DWORD_PTR unsigned __int64 + #else + #define DWORD_PTR unsigned long + #endif #endif /************************************************* Constants ********/ @@ -205,6 +212,34 @@ Non-critical stuff for the future: static const char constInputMapperSuffix_[] = " - Input"; static const char constOutputMapperSuffix_[] = " - Output"; +/* +copies TCHAR string to explicit char string +*/ +char *StrTCpyToC(char *to, const TCHAR *from) +{ +#if !defined(_UNICODE) && !defined(UNICODE) + return strcpy(to, from); +#else + int count = wcslen(from); + if (count != 0) + if (WideCharToMultiByte(CP_ACP, 0, from, count, to, count, NULL, NULL) == 0) + return NULL; + return to; +#endif +} + +/* +returns length of TCHAR string +*/ +size_t StrTLen(const TCHAR *str) +{ +#if !defined(_UNICODE) && !defined(UNICODE) + return strlen(str); +#else + return wcslen(str); +#endif +} + /********************************************************************/ typedef struct PaWinMmeStream PaWinMmeStream; /* forward declaration */ @@ -685,25 +720,25 @@ static PaError InitializeInputDeviceInfo( PaWinMmeHostApiRepresentation *winMmeH { /* Append I/O suffix to WAVE_MAPPER device. */ deviceName = (char *)PaUtil_GroupAllocateMemory( - winMmeHostApi->allocations, strlen( wic.szPname ) + 1 + sizeof(constInputMapperSuffix_) ); + winMmeHostApi->allocations, StrTLen( wic.szPname ) + 1 + sizeof(constInputMapperSuffix_) ); if( !deviceName ) { result = paInsufficientMemory; goto error; } - strcpy( deviceName, wic.szPname ); + StrTCpyToC( deviceName, wic.szPname ); strcat( deviceName, constInputMapperSuffix_ ); } else { deviceName = (char*)PaUtil_GroupAllocateMemory( - winMmeHostApi->allocations, strlen( wic.szPname ) + 1 ); + winMmeHostApi->allocations, StrTLen( wic.szPname ) + 1 ); if( !deviceName ) { result = paInsufficientMemory; goto error; } - strcpy( deviceName, wic.szPname ); + StrTCpyToC( deviceName, wic.szPname ); } deviceInfo->name = deviceName; @@ -808,25 +843,25 @@ static PaError InitializeOutputDeviceInfo( PaWinMmeHostApiRepresentation *winMme { /* Append I/O suffix to WAVE_MAPPER device. */ deviceName = (char *)PaUtil_GroupAllocateMemory( - winMmeHostApi->allocations, strlen( woc.szPname ) + 1 + sizeof(constOutputMapperSuffix_) ); + winMmeHostApi->allocations, StrTLen( woc.szPname ) + 1 + sizeof(constOutputMapperSuffix_) ); if( !deviceName ) { result = paInsufficientMemory; goto error; } - strcpy( deviceName, woc.szPname ); + StrTCpyToC( deviceName, woc.szPname ); strcat( deviceName, constOutputMapperSuffix_ ); } else { deviceName = (char*)PaUtil_GroupAllocateMemory( - winMmeHostApi->allocations, strlen( woc.szPname ) + 1 ); + winMmeHostApi->allocations, StrTLen( woc.szPname ) + 1 ); if( !deviceName ) { result = paInsufficientMemory; goto error; } - strcpy( deviceName, woc.szPname ); + StrTCpyToC( deviceName, woc.szPname ); } deviceInfo->name = deviceName; @@ -940,11 +975,11 @@ PaError PaWinMme_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd /* the following calls assume that if wave*Message fails the preferred device parameter won't be modified */ preferredDeviceStatusFlags = 0; waveInPreferredDevice = -1; - waveInMessage( (HWAVEIN)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD)&waveInPreferredDevice, (DWORD)&preferredDeviceStatusFlags ); + waveInMessage( (HWAVEIN)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&waveInPreferredDevice, (DWORD_PTR)&preferredDeviceStatusFlags ); preferredDeviceStatusFlags = 0; waveOutPreferredDevice = -1; - waveOutMessage( (HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD)&waveOutPreferredDevice, (DWORD)&preferredDeviceStatusFlags ); + waveOutMessage( (HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&waveOutPreferredDevice, (DWORD_PTR)&preferredDeviceStatusFlags ); maximumPossibleDeviceCount = 0; @@ -2092,7 +2127,7 @@ struct PaWinMmeStream /* Processing thread management -------------- */ HANDLE abortEvent; HANDLE processingThread; - DWORD processingThreadId; + PA_THREAD_ID processingThreadId; char throttleProcessingThreadOnOverload; /* 0 -> don't throtte, non-0 -> throttle */ int processingThreadPriority; @@ -2758,7 +2793,7 @@ static PaError CatchUpOutputBuffers( PaWinMmeStream *stream ) } -static DWORD WINAPI ProcessingThreadProc( void *pArg ) +PA_THREAD_FUNC ProcessingThreadProc( void *pArg ) { PaWinMmeStream *stream = (PaWinMmeStream *)pArg; HANDLE events[3];