From e71e7e1cd3b8da1bded3a026935721ec8e9729d9 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Thu, 20 Nov 2014 13:44:35 +0000 Subject: [PATCH] Catched exception while getting active desktop name --- src/lib/platform/MSWindowsSession.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/platform/MSWindowsSession.cpp b/src/lib/platform/MSWindowsSession.cpp index 9318ceea..177ce6d9 100644 --- a/src/lib/platform/MSWindowsSession.cpp +++ b/src/lib/platform/MSWindowsSession.cpp @@ -176,15 +176,19 @@ String MSWindowsSession::getActiveDesktopName() { String result; - - HDESK hd = OpenInputDesktop(0, TRUE, GENERIC_READ); - if (hd != NULL) { - DWORD size; - GetUserObjectInformation(hd, UOI_NAME, NULL, 0, &size); - TCHAR* name = (TCHAR*)alloca(size + sizeof(TCHAR)); - GetUserObjectInformation(hd, UOI_NAME, name, size, &size); - result = name; - CloseDesktop(hd); + try { + HDESK hd = OpenInputDesktop(0, TRUE, GENERIC_READ); + if (hd != NULL) { + DWORD size; + GetUserObjectInformation(hd, UOI_NAME, NULL, 0, &size); + TCHAR* name = (TCHAR*)alloca(size + sizeof(TCHAR)); + GetUserObjectInformation(hd, UOI_NAME, name, size, &size); + result = name; + CloseDesktop(hd); + } + } + catch (std::exception error) { + LOG((CLOG_ERR "failed to get active desktop name: %s", error.what())); } return result;