Disabled system critical error message boxes on startup

http://msdn.microsoft.com/library/windows/desktop/ff805117.aspx
This commit is contained in:
Birunthan Mohanathas 2012-08-12 17:46:23 +03:00
parent cbee39e5d5
commit 2cbdb2b9f2
5 changed files with 21 additions and 41 deletions

View File

@ -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);

View File

@ -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
}
}

View File

@ -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();

View File

@ -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;
}

View File

@ -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);