From bb823b798eca6a4de08422b98424a43d4f250c62 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Fri, 3 May 2013 16:41:21 +0300 Subject: [PATCH] NowPlaying: Add workaround for ATL's broken XP support in VS2012 Update 2 https://connect.microsoft.com/VisualStudio/feedback/details/783276/vs2012-2-v110-xp-broken-the-procedure-entry-point-initializecriticalsectionex-could-not-be-located-in-the-dynamic-link-library-kernel32-dll --- .../PluginNowPlaying/PluginNowPlaying.vcxproj | 15 ++++++ .../PluginNowPlaying.vcxproj.filters | 14 +++++ Plugins/PluginNowPlaying/XPATL.cpp | 53 +++++++++++++++++++ Plugins/PluginNowPlaying/XPATLx64.asm | 34 ++++++++++++ Plugins/PluginNowPlaying/XPATLx86.asm | 42 +++++++++++++++ 5 files changed, 158 insertions(+) create mode 100644 Plugins/PluginNowPlaying/XPATL.cpp create mode 100644 Plugins/PluginNowPlaying/XPATLx64.asm create mode 100644 Plugins/PluginNowPlaying/XPATLx86.asm diff --git a/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj b/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj index 46078fe2..46b86088 100644 --- a/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj +++ b/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj @@ -11,6 +11,7 @@ + @@ -144,6 +145,7 @@ + @@ -170,7 +172,20 @@ + + + Document + true + true + + + Document + true + true + + + \ No newline at end of file diff --git a/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj.filters b/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj.filters index 7eda38c5..6ae693fa 100644 --- a/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj.filters +++ b/Plugins/PluginNowPlaying/PluginNowPlaying.vcxproj.filters @@ -25,6 +25,9 @@ {abad9374-731c-48b4-8ae1-45793b348013} + + {d22781ac-b5c3-48db-b89f-3429215cc8cf} + @@ -270,6 +273,9 @@ Source Files + + XPATL + @@ -338,4 +344,12 @@ Source Files + + + XPATL + + + XPATL + + \ No newline at end of file diff --git a/Plugins/PluginNowPlaying/XPATL.cpp b/Plugins/PluginNowPlaying/XPATL.cpp new file mode 100644 index 00000000..fa8d48e7 --- /dev/null +++ b/Plugins/PluginNowPlaying/XPATL.cpp @@ -0,0 +1,53 @@ +/* Copyright (c) 2013 Mike Ryan + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software +and associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + + +// XPSupport ATL Wrappers (for VC2012 Update 2) +// Written by Mike Ryan (aka Ted.) +// http://tedwvc.wordpress.com + +// 2013-04-14 1.00 initial release to wrap InitializeCriticalSectionEx +// 2013-04-15 1.01 added x64 asm file (no change to CPP file) +// 2013-04-17 1.02 cleaned up Vista check (was triggering RTCs) + +#include "StdAfx.h" + +bool Is_VistaOrLater() { + DWORD version = ::GetVersion(); + DWORD major = (DWORD) (LOBYTE(LOWORD(version))); + + return (major >= 6); +} + +typedef BOOL (WINAPI *pInitializeCriticalSectionEx)(__out LPCRITICAL_SECTION lpCriticalSection, __in DWORD dwSpinCount, __in DWORD Flags); + +extern "C" BOOL WINAPI VC11Update2InitializeCriticalSectionEx(__out LPCRITICAL_SECTION lpCriticalSection, __in DWORD dwSpinCount, __in DWORD Flags) +{ + static pInitializeCriticalSectionEx InitializeCriticalSectionEx_p = NULL; + + if (Is_VistaOrLater()) { // Vista or higher + if (!InitializeCriticalSectionEx_p) { + HMODULE mod = GetModuleHandle(L"KERNEL32.DLL"); + if (mod) + InitializeCriticalSectionEx_p = (pInitializeCriticalSectionEx) GetProcAddress(mod, "InitializeCriticalSectionEx"); + } + return InitializeCriticalSectionEx_p(lpCriticalSection, dwSpinCount, Flags); + } + + // on XP we'll use InitializeCrticialSectionAndSpinCount + return ::InitializeCriticalSectionAndSpinCount(lpCriticalSection, dwSpinCount); +} diff --git a/Plugins/PluginNowPlaying/XPATLx64.asm b/Plugins/PluginNowPlaying/XPATLx64.asm new file mode 100644 index 00000000..ae16cbe1 --- /dev/null +++ b/Plugins/PluginNowPlaying/XPATLx64.asm @@ -0,0 +1,34 @@ +;Copyright (c) 2013 Mike Ryan + +;Permission is hereby granted, free of charge, to any person obtaining a copy of this software +;and associated documentation files (the "Software"), to deal in the Software without restriction, +;including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +;and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +;subject to the following conditions: + +;The above copyright notice and this permission notice shall be included in all copies or substantial +;portions of the Software. + +;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +;LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +;IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +;WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +;OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +__ML_64 = OPATTR rax + +IF __ML_64 + +VC11Update2InitializeCriticalSectionEx PROTO :QWORD,:DWORD,:DWORD + +.data + __imp_InitializeCriticalSectionEx dq VC11Update2InitializeCriticalSectionEx + + EXTERNDEF __imp_InitializeCriticalSectionEx : DWORD + +.code + +ENDIF + +end + diff --git a/Plugins/PluginNowPlaying/XPATLx86.asm b/Plugins/PluginNowPlaying/XPATLx86.asm new file mode 100644 index 00000000..66bb2c2a --- /dev/null +++ b/Plugins/PluginNowPlaying/XPATLx86.asm @@ -0,0 +1,42 @@ +;Copyright (c) 2013 Mike Ryan + +;Permission is hereby granted, free of charge, to any person obtaining a copy of this software +;and associated documentation files (the "Software"), to deal in the Software without restriction, +;including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, +;and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, +;subject to the following conditions: + +;The above copyright notice and this permission notice shall be included in all copies or substantial +;portions of the Software. + +;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +;LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +;IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +;WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +;OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +__ML_64 = OPATTR rax + +IF __ML_64 +ELSE + +.model flat, C + + +VC11Update2InitializeCriticalSectionEx PROTO STDCALL :DWORD,:DWORD,:DWORD + +.data + + __imp__InitializeCriticalSectionEx@12 dd VC11Update2InitializeCriticalSectionEx + + EXTERNDEF __imp__InitializeCriticalSectionEx@12 : DWORD + +.code + +ENDIF + +end + + + +