win_util.cpp (1277B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 // This is a partial implementation of Chromium's source file 8 // base/win/win_util.cc 9 10 #include "base/win/win_util.h" 11 12 #include <windows.h> 13 14 #include "base/logging.h" 15 #include "base/strings/string_util.h" 16 17 namespace base { 18 namespace win { 19 20 const char kApplicationVerifierDllName[] = "verifier.dll"; 21 22 std::wstring GetWindowObjectName(HANDLE handle) { 23 // Get the size of the name. 24 std::wstring object_name; 25 26 DWORD size = 0; 27 ::GetUserObjectInformation(handle, UOI_NAME, nullptr, 0, &size); 28 if (!size) { 29 DPCHECK(false); 30 return object_name; 31 } 32 33 LOG_ASSERT(size % sizeof(wchar_t) == 0u); 34 35 // Query the name of the object. 36 if (!::GetUserObjectInformation( 37 handle, UOI_NAME, WriteInto(&object_name, size / sizeof(wchar_t)), 38 size, &size)) { 39 DPCHECK(false); 40 } 41 42 return object_name; 43 } 44 45 bool IsAppVerifierLoaded() { 46 return GetModuleHandleA(kApplicationVerifierDllName); 47 } 48 49 } // namespace win 50 } // namespace base