OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" | 5 #include "cloud_print/virtual_driver/win/virtual_driver_helpers.h" |
6 #include <windows.h> | 6 #include <windows.h> |
7 #include <winspool.h> | 7 #include <winspool.h> |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "cloud_print/virtual_driver/win/virtual_driver_consts.h" | 9 #include "base/logging.h" |
10 #include "base/string16.h" | |
11 #include "base/win/windows_version.h" | |
10 | 12 |
11 namespace cloud_print { | 13 namespace cloud_print { |
12 | 14 |
13 const size_t kMaxMessageLen = 100; | 15 const size_t kMaxMessageLen = 100; |
14 | 16 |
15 void DisplayWindowsMessage(HWND hwnd, HRESULT message_id) { | 17 void DisplayWindowsMessage(HWND hwnd, |
18 HRESULT message_id, | |
19 const string16 &caption) { | |
16 wchar_t message_text[kMaxMessageLen + 1] = L""; | 20 wchar_t message_text[kMaxMessageLen + 1] = L""; |
17 | 21 |
18 ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, | 22 ::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, |
19 NULL, | 23 NULL, |
20 message_id, | 24 message_id, |
21 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 25 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
22 message_text, | 26 message_text, |
23 kMaxMessageLen, | 27 kMaxMessageLen, |
24 NULL); | 28 NULL); |
25 ::MessageBox(hwnd, message_text, kVirtualDriverName, MB_OK); | 29 ::MessageBox(hwnd, message_text, caption.c_str(), MB_OK); |
26 } | 30 } |
27 | 31 |
28 HRESULT GetLastHResult() { | 32 HRESULT GetLastHResult() { |
29 DWORD error_code = GetLastError(); | 33 DWORD error_code = GetLastError(); |
30 return HRESULT_FROM_WIN32(error_code); | 34 return HRESULT_FROM_WIN32(error_code); |
31 } | 35 } |
32 | 36 |
37 void GetPortMonitorDllName(FilePath* path) { | |
38 string16 dll_name; | |
39 if (IsSystem64Bit()) { | |
40 *path = FilePath(L"gcp_portmon64.dll"); | |
41 } else { | |
42 *path = FilePath(L"gcp_portmon32.dll"); | |
43 } | |
44 } | |
45 | |
33 HRESULT GetPrinterDriverDir(FilePath* path) { | 46 HRESULT GetPrinterDriverDir(FilePath* path) { |
34 BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)]; | 47 BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)]; |
35 DWORD needed = 0; | 48 DWORD needed = 0; |
36 if (!GetPrinterDriverDirectory(NULL, | 49 if (!GetPrinterDriverDirectory(NULL, |
37 NULL, | 50 NULL, |
38 1, | 51 1, |
39 driver_dir_buffer, | 52 driver_dir_buffer, |
40 MAX_PATH * sizeof(wchar_t), | 53 MAX_PATH * sizeof(wchar_t), |
41 &needed)) { | 54 &needed)) { |
42 // We could try to allocate a larger buffer if needed > MAX_PATH | 55 // We could try to allocate a larger buffer if needed > MAX_PATH |
43 // but that really shouldn't happen. | 56 // but that really shouldn't happen. |
44 return cloud_print::GetLastHResult(); | 57 return cloud_print::GetLastHResult(); |
45 } | 58 } |
46 *path = FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer)); | 59 *path = FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer)); |
47 | 60 |
48 // The XPS driver is a "Level 3" driver | 61 // The XPS driver is a "Level 3" driver |
49 *path = path->Append(L"3"); | 62 *path = path->Append(L"3"); |
50 return S_OK; | 63 return S_OK; |
51 } | 64 } |
65 | |
66 bool IsSystem64Bit() { | |
67 base::win::OSInfo::WindowsArchitecture arch = | |
68 base::win::OSInfo::GetInstance()->architecture(); | |
69 return (arch == base::win::OSInfo::X64_ARCHITECTURE) || | |
70 (arch == base::win::OSInfo::IA64_ARCHITECTURE); | |
52 } | 71 } |
53 | 72 |
73 void LoadLocalString(DWORD string_id, string16* target) { | |
74 static wchar_t dummy = L'\0'; | |
75 static wchar_t buffer[MAX_PATH]; | |
76 HMODULE module = NULL; | |
77 GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | | |
78 GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, | |
79 &dummy, | |
80 &module); | |
81 int count = LoadString(module, | |
82 string_id, | |
83 buffer, | |
84 MAX_PATH); | |
85 DCHECK_NE(0, count); | |
sanjeevr
2011/05/10 16:18:47
Can you change the DCHECK to a CHECK? And also wri
Albert Bodenhamer
2011/05/11 21:46:12
Done.
| |
86 *target = string16(buffer); | |
87 } | |
88 } | |
89 | |
OLD | NEW |