From 150c53af0f4c0f21a76d7b17b7d0d6acbf18ae57 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Thu, 23 Jul 2015 18:58:24 +0100 Subject: [PATCH] spu2-x: windows: Remove Unicode to Ascii conversion Use swscanf instead of sscanf to read wide characters directly --- plugins/spu2-x/src/Windows/Dialogs.h | 2 +- plugins/spu2-x/src/Windows/SndOut_DSound.cpp | 10 ++-------- plugins/spu2-x/src/Windows/UIHelpers.cpp | 4 ++-- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/plugins/spu2-x/src/Windows/Dialogs.h b/plugins/spu2-x/src/Windows/Dialogs.h index e2d7fe03c8..6a7d9f5600 100644 --- a/plugins/spu2-x/src/Windows/Dialogs.h +++ b/plugins/spu2-x/src/Windows/Dialogs.h @@ -40,7 +40,7 @@ namespace SoundtouchCfg } extern int SendDialogMsg( HWND hwnd, int dlgId, UINT code, WPARAM wParam, LPARAM lParam); -extern HRESULT GUIDFromString( const char *str, LPGUID guid ); +extern HRESULT GUIDFromString( const wchar_t *str, LPGUID guid ); extern void AssignSliderValue( HWND idcwnd, HWND hwndDisplay, int value ); extern void AssignSliderValue( HWND hWnd, int idc, int editbox, int value ); diff --git a/plugins/spu2-x/src/Windows/SndOut_DSound.cpp b/plugins/spu2-x/src/Windows/SndOut_DSound.cpp index d173075f6c..a415d0bf4a 100644 --- a/plugins/spu2-x/src/Windows/SndOut_DSound.cpp +++ b/plugins/spu2-x/src/Windows/SndOut_DSound.cpp @@ -117,11 +117,7 @@ public: if( m_Device.empty() ) throw std::runtime_error( "screw it" ); - // Convert from unicode to ANSI: - char guid[256]; - sprintf_s( guid, "%S", m_Device.c_str() ); - - if( (FAILED(GUIDFromString( guid, &cGuid ))) || + if ((FAILED(GUIDFromString(m_Device, &cGuid))) || FAILED( DirectSoundCreate8(&cGuid,&dsound,NULL) ) ) throw std::runtime_error( "try again?" ); } @@ -286,9 +282,7 @@ private: { wchar_t temp[128]; - char temp2[192]; - sprintf_s( temp2, "%S", m_Device.c_str() ); - haveGuid = ! FAILED(GUIDFromString(temp2,&DevGuid)); + haveGuid = !FAILED(GUIDFromString(m_Device, &DevGuid)); SendMessage(GetDlgItem(hWnd,IDC_DS_DEVICE),CB_RESETCONTENT,0,0); ndevs=0; diff --git a/plugins/spu2-x/src/Windows/UIHelpers.cpp b/plugins/spu2-x/src/Windows/UIHelpers.cpp index 2e1be74ca7..19dae47fbd 100644 --- a/plugins/spu2-x/src/Windows/UIHelpers.cpp +++ b/plugins/spu2-x/src/Windows/UIHelpers.cpp @@ -23,7 +23,7 @@ int SendDialogMsg( HWND hwnd, int dlgId, UINT code, WPARAM wParam, LPARAM lParam return SendMessage( GetDlgItem(hwnd,dlgId), code, wParam, lParam ); } -HRESULT GUIDFromString(const char *str, LPGUID guid) +HRESULT GUIDFromString(const wchar_t *str, LPGUID guid) { // "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" @@ -32,7 +32,7 @@ HRESULT GUIDFromString(const char *str, LPGUID guid) int k; // << not used but still needed as of January 6th, 2011 } t; - int r = sscanf_s(str,"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + int r = swscanf_s(str,L"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", &t.g.Data1, &t.g.Data2, &t.g.Data3,