From 92eafce2dce1a3446aed6ec6bc44291c54c6a2d5 Mon Sep 17 00:00:00 2001 From: spx Date: Sun, 30 Jan 2011 09:31:41 +0000 Subject: [PATCH] Disabled the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls in all DLLs. DisableThreadLibraryCalls Function http://msdn.microsoft.com/en-us/library/ms682579.aspx Note: Do not call "DisableThreadLibraryCalls" in a DLL which is statically linked to the CRT http://support.microsoft.com/kb/555563/en-us For plugin author: If you need to implement DllMain entry point yourself, get rid of the #include "DisableThreadLibraryCalls.h" line. --- Library/DisableThreadLibraryCalls.h | 50 +++++++++++++++++++ Library/Library.vcproj | 4 ++ Library/Rainmeter.cpp | 2 + Plugins/PluginAdvancedCPU/AdvancedCPU.cpp | 2 + Plugins/PluginCoreTemp/PluginCoreTemp.cpp | 2 + Plugins/PluginExample/ExamplePlugin.c | 2 + Plugins/PluginFolderInfo/FolderInfoPlugin.cpp | 2 + Plugins/PluginMediaKey/PluginMediaKey.cpp | 2 + Plugins/PluginPerfMon/PerfData.cpp | 2 + Plugins/PluginPing/Ping.cpp | 2 + Plugins/PluginPower/PowerPlugin.cpp | 2 + Plugins/PluginQuote/Quote.cpp | 2 + .../PluginRecycleManager/RecycleManager.cpp | 2 + Plugins/PluginResMon/ResMon.cpp | 2 + Plugins/PluginSpeedFan/SpeedFanPlugin.cpp | 2 + Plugins/PluginSysInfo/SysInfo.cpp | 2 + .../PluginVirtualDesktops/VirtualDesktops.cpp | 2 + Plugins/PluginWebParser/WebParser.cpp | 2 + Plugins/PluginWifiStatus/WifiStatus.cpp | 2 + Plugins/PluginWin7Audio/Win7AudioPlugin.cpp | 2 + .../WindowMessagePlugin.cpp | 2 + Plugins/PluginiTunes/iTunesPlugin.cpp | 2 + 22 files changed, 94 insertions(+) create mode 100644 Library/DisableThreadLibraryCalls.h diff --git a/Library/DisableThreadLibraryCalls.h b/Library/DisableThreadLibraryCalls.h new file mode 100644 index 00000000..ce7e468e --- /dev/null +++ b/Library/DisableThreadLibraryCalls.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2011 spx + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#ifndef _DISABLETHREADLIBRARYCALLS_H_ +#define _DISABLETHREADLIBRARYCALLS_H_ + +// DisableThreadLibraryCalls Function +// http://msdn.microsoft.com/en-us/library/ms682579.aspx +// +// Note: Do not call "DisableThreadLibraryCalls" in a DLL which is statically linked to the CRT +// http://support.microsoft.com/kb/555563/en-us + +#if defined(_DLL) /* /MD */ + +/* +** DllMain +** +** Disables the DLL_THREAD_ATTACH and DLL_THREAD_DETACH notification calls. +** +*/ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + DisableThreadLibraryCalls(hinstDLL); + break; + } + + return TRUE; +} + +#endif + +#endif diff --git a/Library/Library.vcproj b/Library/Library.vcproj index c14c727f..e4a0ab24 100644 --- a/Library/Library.vcproj +++ b/Library/Library.vcproj @@ -2123,6 +2123,10 @@ RelativePath="ConfigParser.h" > + + diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 295c59c2..0921df86 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -26,6 +26,8 @@ #include "Resource.h" #include "UpdateCheck.h" +#include "DisableThreadLibraryCalls.h" // contains DllMain entry point + using namespace Gdiplus; CRainmeter* Rainmeter; // The module diff --git a/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp b/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp index ae1c63f3..548b5e44 100644 --- a/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp +++ b/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp @@ -23,6 +23,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + //ULONGLONG GetPerfData(PCTSTR ObjectName, PCTSTR InstanceName, PCTSTR CounterName); void UpdateProcesses(); diff --git a/Plugins/PluginCoreTemp/PluginCoreTemp.cpp b/Plugins/PluginCoreTemp/PluginCoreTemp.cpp index bb740a4a..17ddd4a4 100644 --- a/Plugins/PluginCoreTemp/PluginCoreTemp.cpp +++ b/Plugins/PluginCoreTemp/PluginCoreTemp.cpp @@ -24,6 +24,8 @@ #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + extern "C" { __declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id); diff --git a/Plugins/PluginExample/ExamplePlugin.c b/Plugins/PluginExample/ExamplePlugin.c index 023351ec..b7960e0e 100644 --- a/Plugins/PluginExample/ExamplePlugin.c +++ b/Plugins/PluginExample/ExamplePlugin.c @@ -22,6 +22,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +//#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ __declspec( dllexport ) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id); __declspec( dllexport ) void Finalize(HMODULE instance, UINT id); diff --git a/Plugins/PluginFolderInfo/FolderInfoPlugin.cpp b/Plugins/PluginFolderInfo/FolderInfoPlugin.cpp index 668bb922..b286f6b9 100644 --- a/Plugins/PluginFolderInfo/FolderInfoPlugin.cpp +++ b/Plugins/PluginFolderInfo/FolderInfoPlugin.cpp @@ -22,6 +22,8 @@ #include #include "FolderInfo.h" +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + #define UPDATE_TIME_MIN_MS 10000 using namespace PluginFolderInfo; diff --git a/Plugins/PluginMediaKey/PluginMediaKey.cpp b/Plugins/PluginMediaKey/PluginMediaKey.cpp index d7bc83fb..6b938418 100644 --- a/Plugins/PluginMediaKey/PluginMediaKey.cpp +++ b/Plugins/PluginMediaKey/PluginMediaKey.cpp @@ -20,6 +20,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginPerfMon/PerfData.cpp b/Plugins/PluginPerfMon/PerfData.cpp index e1b9941b..7def5679 100644 --- a/Plugins/PluginPerfMon/PerfData.cpp +++ b/Plugins/PluginPerfMon/PerfData.cpp @@ -23,6 +23,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + ULONGLONG GetPerfData(PCTSTR ObjectName, PCTSTR InstanceName, PCTSTR CounterName); struct PerfMeasure diff --git a/Plugins/PluginPing/Ping.cpp b/Plugins/PluginPing/Ping.cpp index e693e515..0b9bc389 100644 --- a/Plugins/PluginPing/Ping.cpp +++ b/Plugins/PluginPing/Ping.cpp @@ -29,6 +29,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginPower/PowerPlugin.cpp b/Plugins/PluginPower/PowerPlugin.cpp index 274ace25..d25fcdbb 100644 --- a/Plugins/PluginPower/PowerPlugin.cpp +++ b/Plugins/PluginPower/PowerPlugin.cpp @@ -26,6 +26,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + typedef struct _PROCESSOR_POWER_INFORMATION { ULONG Number; diff --git a/Plugins/PluginQuote/Quote.cpp b/Plugins/PluginQuote/Quote.cpp index 0e6bcf31..104ba032 100644 --- a/Plugins/PluginQuote/Quote.cpp +++ b/Plugins/PluginQuote/Quote.cpp @@ -28,6 +28,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginRecycleManager/RecycleManager.cpp b/Plugins/PluginRecycleManager/RecycleManager.cpp index 0ca31488..f6424350 100644 --- a/Plugins/PluginRecycleManager/RecycleManager.cpp +++ b/Plugins/PluginRecycleManager/RecycleManager.cpp @@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginResMon/ResMon.cpp b/Plugins/PluginResMon/ResMon.cpp index e41d811f..abfc06a5 100644 --- a/Plugins/PluginResMon/ResMon.cpp +++ b/Plugins/PluginResMon/ResMon.cpp @@ -34,6 +34,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp b/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp index 9abd2a4e..2d6d26ec 100644 --- a/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp +++ b/Plugins/PluginSpeedFan/SpeedFanPlugin.cpp @@ -24,6 +24,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginSysInfo/SysInfo.cpp b/Plugins/PluginSysInfo/SysInfo.cpp index c3a62346..925a4b3c 100644 --- a/Plugins/PluginSysInfo/SysInfo.cpp +++ b/Plugins/PluginSysInfo/SysInfo.cpp @@ -26,6 +26,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginVirtualDesktops/VirtualDesktops.cpp b/Plugins/PluginVirtualDesktops/VirtualDesktops.cpp index 38f182ea..b24aaf98 100644 --- a/Plugins/PluginVirtualDesktops/VirtualDesktops.cpp +++ b/Plugins/PluginVirtualDesktops/VirtualDesktops.cpp @@ -72,6 +72,8 @@ #include "../../Library/Export.h" +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + extern "C" { __declspec(dllexport) UINT Initialize(HMODULE instance, LPCTSTR iniFile, LPCTSTR section, UINT id); diff --git a/Plugins/PluginWebParser/WebParser.cpp b/Plugins/PluginWebParser/WebParser.cpp index 54ea1aef..37a03244 100644 --- a/Plugins/PluginWebParser/WebParser.cpp +++ b/Plugins/PluginWebParser/WebParser.cpp @@ -32,6 +32,8 @@ #include "..\..\Library\pcre-8.10/pcre.h" #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginWifiStatus/WifiStatus.cpp b/Plugins/PluginWifiStatus/WifiStatus.cpp index 6c82bb29..6ddbfcbb 100644 --- a/Plugins/PluginWifiStatus/WifiStatus.cpp +++ b/Plugins/PluginWifiStatus/WifiStatus.cpp @@ -26,6 +26,8 @@ along with this program. If not, see . #pragma comment( lib, "wlanapi.lib") #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp b/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp index 216b3d75..5c537500 100644 --- a/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp +++ b/Plugins/PluginWin7Audio/Win7AudioPlugin.cpp @@ -32,6 +32,8 @@ #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + #define SAFE_RELEASE(punk) \ if ((punk) != NULL) { (punk)->Release(); (punk) = NULL; } diff --git a/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp b/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp index faf6e8fe..49a8b5e0 100644 --- a/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp +++ b/Plugins/PluginWindowMessage/WindowMessagePlugin.cpp @@ -26,6 +26,8 @@ #include #include "..\..\Library\Export.h" // Rainmeter's exported functions +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + /* The exported functions */ extern "C" { diff --git a/Plugins/PluginiTunes/iTunesPlugin.cpp b/Plugins/PluginiTunes/iTunesPlugin.cpp index b72a5d38..cc797a08 100644 --- a/Plugins/PluginiTunes/iTunesPlugin.cpp +++ b/Plugins/PluginiTunes/iTunesPlugin.cpp @@ -25,6 +25,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include +#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point + const int VOLUME_STEP = 5; /* The exported functions */