summaryrefslogtreecommitdiff
path: root/zen/notify_removal.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2015-10-02 14:49:33 +0200
committerDaniel Wilhelm <daniel@wili.li>2015-10-02 14:49:33 +0200
commita6e9143baf48bdc093788545636570808f9c103c (patch)
treed223a9360134cd8105a96ee0faf5c2643bd9141b /zen/notify_removal.cpp
parent6.4 (diff)
downloadFreeFileSync-a6e9143baf48bdc093788545636570808f9c103c.tar.gz
FreeFileSync-a6e9143baf48bdc093788545636570808f9c103c.tar.bz2
FreeFileSync-a6e9143baf48bdc093788545636570808f9c103c.zip
6.5
Diffstat (limited to 'zen/notify_removal.cpp')
-rw-r--r--zen/notify_removal.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/zen/notify_removal.cpp b/zen/notify_removal.cpp
index 678675b5..c66eb3c1 100644
--- a/zen/notify_removal.cpp
+++ b/zen/notify_removal.cpp
@@ -75,7 +75,7 @@ MessageProvider::MessageProvider() :
windowHandle(nullptr)
{
if (!hMainModule)
- throw FileError(_("Unable to register to receive system messages."), formatSystemError(L"GetModuleHandle", getLastError()));
+ throwFileError(_("Unable to register to receive system messages."), L"GetModuleHandle", getLastError());
//register the main window class
WNDCLASS wc = {};
@@ -84,7 +84,7 @@ MessageProvider::MessageProvider() :
wc.lpszClassName = dummyWindowName;
if (::RegisterClass(&wc) == 0)
- throw FileError(_("Unable to register to receive system messages."), formatSystemError(L"RegisterClass", getLastError()));
+ throwFileError(_("Unable to register to receive system messages."), L"RegisterClass", getLastError());
ScopeGuard guardClass = makeGuard([&] { ::UnregisterClass(dummyWindowName, hMainModule); });
@@ -101,14 +101,17 @@ MessageProvider::MessageProvider() :
hMainModule, //HINSTANCE hInstance,
nullptr); //LPVOID lpParam
if (!windowHandle)
- throw FileError(_("Unable to register to receive system messages."), formatSystemError(L"CreateWindow", getLastError()));
+ throwFileError(_("Unable to register to receive system messages."), L"CreateWindow", getLastError());
//store this-pointer for topWndProc() to use: do this AFTER CreateWindow() to avoid processing messages while this constructor is running!!!
//unlike: http://blogs.msdn.com/b/oldnewthing/archive/2014/02/03/10496248.aspx
::SetLastError(ERROR_SUCCESS); //[!] required for proper error handling, see MSDN, SetWindowLongPtr
if (::SetWindowLongPtr(windowHandle, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this)) == 0)
- if (::GetLastError() != ERROR_SUCCESS)
- throw FileError(_("Unable to register to receive system messages."), formatSystemError(L"SetWindowLongPtr", getLastError()));
+ {
+ const DWORD lastError = ::GetLastError(); //copy before directly or indirectly making other system calls!
+ if (lastError != ERROR_SUCCESS)
+ throwFileError(_("Unable to register to receive system messages."), L"SetWindowLongPtr", lastError);
+ }
guardClass.dismiss();
}
@@ -152,11 +155,11 @@ public:
DEVICE_NOTIFY_WINDOW_HANDLE); //__in DWORD Flags
if (!hNotification)
{
- const DWORD lastError = ::GetLastError();
+ const DWORD lastError = ::GetLastError(); //copy before directly or indirectly making other system calls!
if (lastError != ERROR_CALL_NOT_IMPLEMENTED && //fail on SAMBA share: this shouldn't be a showstopper!
lastError != ERROR_SERVICE_SPECIFIC_ERROR && //neither should be fail for "Pogoplug" mapped network drives
lastError != ERROR_INVALID_DATA) //this seems to happen for a NetDrive-mapped FTP server
- throw zen::FileError(_("Unable to register to receive system messages."), formatSystemError(L"RegisterDeviceNotification", lastError));
+ throwFileError(_("Unable to register to receive system messages."), L"RegisterDeviceNotification", lastError);
}
guardProvider.dismiss();
bgstack15