forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvirtual_driver_helpers.cc
52 lines (42 loc) · 1.59 KB
/
virtual_driver_helpers.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cloud_print/virtual_driver/win/virtual_driver_helpers.h"
#include <windows.h>
#include <winspool.h>
#include <string>
#include "base/files/file_util.h"
#include "base/win/windows_version.h"
#include "cloud_print/common/win/cloud_print_utils.h"
namespace cloud_print {
void DisplayWindowsMessage(HWND hwnd, HRESULT hr, const std::wstring& caption) {
::MessageBox(hwnd, GetErrorMessage(hr).c_str(), caption.c_str(), MB_OK);
}
std::wstring GetPortMonitorDllName() {
if (IsSystem64Bit()) {
return std::wstring(L"gcp_portmon64.dll");
} else {
return std::wstring(L"gcp_portmon.dll");
}
}
HRESULT GetPrinterDriverDir(base::FilePath* path) {
BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)];
DWORD needed = 0;
if (!GetPrinterDriverDirectory(NULL, NULL, 1, driver_dir_buffer,
MAX_PATH * sizeof(wchar_t), &needed)) {
// We could try to allocate a larger buffer if needed > MAX_PATH
// but that really shouldn't happen.
return cloud_print::GetLastHResult();
}
*path = base::FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer));
// The XPS driver is a "Level 3" driver
*path = path->Append(L"3");
return S_OK;
}
bool IsSystem64Bit() {
base::win::OSInfo::WindowsArchitecture arch =
base::win::OSInfo::GetArchitecture();
return (arch == base::win::OSInfo::X64_ARCHITECTURE) ||
(arch == base::win::OSInfo::IA64_ARCHITECTURE);
}
} // namespace cloud_print