From 2a0dbe4e744951c264a0cd555a4ab0eadc483a7d Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Tue, 13 Oct 2009 18:12:33 +0000 Subject: [PATCH] - LIB: Make the is_remote_desktop compilable for all VS versions and SKUs. lib/ win_util.cpp, .h svn path=/trunk/boinc/; revision=19296 --- checkin_notes | 7 +++++++ lib/win_util.cpp | 53 +++++++++++++++++++++++++++++++----------------- lib/win_util.h | 1 + 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/checkin_notes b/checkin_notes index 650caf1fea..3dcf63877d 100644 --- a/checkin_notes +++ b/checkin_notes @@ -8593,3 +8593,10 @@ David 13 Oct 2009 sched/ sched_locality.cpp + +Rom 13 Oct 2009 + - LIB: Make the is_remote_desktop compilable for all VS versions + and SKUs. + + lib/ + win_util.cpp, .h diff --git a/lib/win_util.cpp b/lib/win_util.cpp index 126c035d5c..26243fe7ea 100644 --- a/lib/win_util.cpp +++ b/lib/win_util.cpp @@ -22,8 +22,6 @@ #include "boinc_win.h" #endif -//#include // not present on academic version of VS2005! - #include "win_util.h" @@ -834,31 +832,48 @@ void chdir_to_data_dir() { } -#if 0 - // return true if running under remote desktop // (in which case CUDA apps don't work) // +typedef BOOL (__stdcall *tWTSQSI)( IN HANDLE, IN DWORD, IN DWORD, OUT LPTSTR*, OUT DWORD* ); +typedef VOID (__stdcall *tWTSFM)( IN PVOID ); + bool is_remote_desktop() { - LPTSTR *buf; - DWORD len; + static HMODULE wtsapi32lib = NULL; + static tWTSQSI pWTSQSI = NULL; + static tWTSFM pWTSFM = NULL; + LPTSTR pBuf = NULL; + DWORD dwLength; - if (WTSQuerySessionInformation( - WTS_CURRENT_SERVER_HANDLE, - WTS_CURRENT_SESSION, - WTSClientProtocolType, - &buf, - &len - )) { + if (!wtsapi32lib) { + wtsapi32lib = LoadLibrary("wtsapi32.dll"); + if (wtsapi32lib) { + pWTSQSI = (tWTSQSI)GetProcAddress(wtsapi32lib, "WTSQuerySessionInformation"); + pWTSFM = (tWTSFM)GetProcAddress(wtsapi32lib, "WTSFreeMemory"); + } + } - USHORT prot = *(USHORT*) buf; - WTSFreeMemory(buf); - - if (prot == 2) return true; + // WTSQuerySessionInformation( + // WTS_CURRENT_SERVER_HANDLE, + // WTS_CURRENT_SESSION, + // WTSClientProtocolType, + // &pBuf, + // &dwLength + // ); + if (pWTSQSI) { + if (pWTSQSI( + (HANDLE)NULL, + (DWORD)-1, + (DWORD)16, + &pBuf, + &dwLength + )) { + USHORT prot = *(USHORT*)pBuf; + pWTSFM(pBuf); + if (prot == 2) return true; + } } return false; } -#endif - diff --git a/lib/win_util.h b/lib/win_util.h index e905e81dea..5de30882a6 100644 --- a/lib/win_util.h +++ b/lib/win_util.h @@ -48,5 +48,6 @@ inline std::string W2A(const std::wstring& str) { extern int suspend_or_resume_threads(DWORD pid, bool resume); extern void chdir_to_data_dir(); +extern bool is_remote_desktop(); #endif // _WIN_UTIL_