Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cloud_print / virtual_driver / win / virtual_driver_helpers.cc
blobda4ec5c6fa47f527546275b8ab2e5d3fcb0fa710
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
7 #include <windows.h>
8 #include <winspool.h>
10 #include "base/files/file_util.h"
11 #include "base/logging.h"
12 #include "base/strings/string16.h"
13 #include "base/win/windows_version.h"
14 #include "cloud_print/common/win/cloud_print_utils.h"
16 namespace cloud_print {
18 void DisplayWindowsMessage(HWND hwnd, HRESULT hr,
19 const base::string16 &caption) {
20 ::MessageBox(hwnd, GetErrorMessage(hr).c_str(), caption.c_str(), MB_OK);
23 base::string16 GetPortMonitorDllName() {
24 if (IsSystem64Bit()) {
25 return base::string16(L"gcp_portmon64.dll");
26 } else {
27 return base::string16(L"gcp_portmon.dll");
31 HRESULT GetPrinterDriverDir(base::FilePath* path) {
32 BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)];
33 DWORD needed = 0;
34 if (!GetPrinterDriverDirectory(NULL,
35 NULL,
37 driver_dir_buffer,
38 MAX_PATH * sizeof(wchar_t),
39 &needed)) {
40 // We could try to allocate a larger buffer if needed > MAX_PATH
41 // but that really shouldn't happen.
42 return cloud_print::GetLastHResult();
44 *path = base::FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer));
46 // The XPS driver is a "Level 3" driver
47 *path = path->Append(L"3");
48 return S_OK;
51 bool IsSystem64Bit() {
52 base::win::OSInfo::WindowsArchitecture arch =
53 base::win::OSInfo::GetInstance()->architecture();
54 return (arch == base::win::OSInfo::X64_ARCHITECTURE) ||
55 (arch == base::win::OSInfo::IA64_ARCHITECTURE);