From 2cbdb2b9f2bb7a819114fdd67d6d7ba0b8526292 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 12 Aug 2012 17:46:23 +0300 Subject: [PATCH] Disabled system critical error message boxes on startup http://msdn.microsoft.com/library/windows/desktop/ff805117.aspx --- Library/DialogAbout.cpp | 2 +- Library/MeasureDiskSpace.cpp | 39 +++++++++++++----------------------- Library/Rainmeter.cpp | 4 ++++ Library/System.cpp | 15 +------------- Library/System.h | 2 +- 5 files changed, 21 insertions(+), 41 deletions(-) diff --git a/Library/DialogAbout.cpp b/Library/DialogAbout.cpp index a97efb8e..34055ea5 100644 --- a/Library/DialogAbout.cpp +++ b/Library/DialogAbout.cpp @@ -1002,7 +1002,7 @@ void CDialogAbout::CTabPlugins::Initialize() // Try old calling GetPluginVersion/GetPluginAuthor for backwards compatibility DWORD err = 0; - HMODULE dll = CSystem::RmLoadLibrary(path, &err, true); + HMODULE dll = CSystem::RmLoadLibrary(path, &err); if (dll) { ListView_InsertItem(item, &vitem); diff --git a/Library/MeasureDiskSpace.cpp b/Library/MeasureDiskSpace.cpp index fe81ff94..fbd79c38 100644 --- a/Library/MeasureDiskSpace.cpp +++ b/Library/MeasureDiskSpace.cpp @@ -107,21 +107,17 @@ void CMeasureDiskSpace::UpdateValue() BOOL sizeResult = FALSE; ULONGLONG i64TotalBytes, i64FreeBytes; - if (type != DRIVE_NO_ROOT_DIR) + if (type != DRIVE_NO_ROOT_DIR && + type != DRIVE_CDROM && + (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives { - if (type != DRIVE_CDROM && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives + if (!m_DiskQuota) { - UINT oldMode = SetErrorMode(0); - SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box - if (!m_DiskQuota) - { - sizeResult = GetDiskFreeSpaceEx(drive, NULL, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); - } - else - { - sizeResult = GetDiskFreeSpaceEx(drive, (PULARGE_INTEGER)&i64FreeBytes, (PULARGE_INTEGER)&i64TotalBytes, NULL); - } - SetErrorMode(oldMode); // Reset + sizeResult = GetDiskFreeSpaceEx(drive, NULL, (PULARGE_INTEGER)&i64TotalBytes, (PULARGE_INTEGER)&i64FreeBytes); + } + else + { + sizeResult = GetDiskFreeSpaceEx(drive, (PULARGE_INTEGER)&i64FreeBytes, (PULARGE_INTEGER)&i64TotalBytes, NULL); } } @@ -148,15 +144,10 @@ void CMeasureDiskSpace::UpdateValue() BOOL labelResult = FALSE; WCHAR volumeName[MAX_PATH + 1]; - if (type != DRIVE_NO_ROOT_DIR) + if (type != DRIVE_NO_ROOT_DIR && + (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore removable drives { - if (!m_IgnoreRemovable || type != DRIVE_REMOVABLE) // Ignore removable drives - { - UINT oldMode = SetErrorMode(0); - SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box - labelResult = GetVolumeInformation(drive, volumeName, MAX_PATH + 1, NULL, NULL, NULL, NULL, 0); - SetErrorMode(oldMode); // Reset - } + labelResult = GetVolumeInformation(drive, volumeName, MAX_PATH + 1, NULL, NULL, NULL, NULL, 0); } m_DriveInfo = (labelResult) ? volumeName : L""; @@ -224,12 +215,10 @@ void CMeasureDiskSpace::ReadOptions(CConfigParser& parser, const WCHAR* section) const WCHAR* drive = m_Drive.c_str(); UINT type = GetDriveType(drive); if (type != DRIVE_NO_ROOT_DIR && - type != DRIVE_CDROM && (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives + type != DRIVE_CDROM && + (!m_IgnoreRemovable || type != DRIVE_REMOVABLE)) // Ignore CD-ROMS and removable drives { - UINT oldMode = SetErrorMode(0); - SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box result = GetDiskFreeSpaceEx(drive, NULL, (PULARGE_INTEGER)&i64TotalBytes, NULL); - SetErrorMode(oldMode); // Reset } } diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index ccc382af..589b2740 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -673,6 +673,10 @@ CRainmeter::CRainmeter() : m_GDIplusToken(), m_GlobalOptions() { + // Prevent the system error message boxes. + UINT oldMode = SetErrorMode(0); + SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); InitCommonControls(); diff --git a/Library/System.cpp b/Library/System.cpp index ea34b168..bb3e93ee 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -1074,16 +1074,8 @@ bool CSystem::IsFileWritable(LPCWSTR file) ** Avoids loading a DLL from current directory. ** */ -HMODULE CSystem::RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError, bool ignoreErrors) +HMODULE CSystem::RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError) { - UINT oldMode; - - if (ignoreErrors) - { - oldMode = SetErrorMode(0); - SetErrorMode(oldMode | SEM_FAILCRITICALERRORS); // Prevent the system from displaying message box - } - // Remove current directory from DLL search path SetDllDirectory(L""); @@ -1095,11 +1087,6 @@ HMODULE CSystem::RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError, bool ignor *dwError = GetLastError(); } - if (ignoreErrors) - { - SetErrorMode(oldMode); // Reset - } - return hLib; } diff --git a/Library/System.h b/Library/System.h index ed5b3ad2..28949fd6 100644 --- a/Library/System.h +++ b/Library/System.h @@ -76,7 +76,7 @@ public: static bool IsFileWritable(LPCWSTR file); - static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false); + static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL); static void ResetWorkingDirectory(); static void SetClipboardText(const std::wstring& text);