Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2026)

Side by Side Diff: cloud_print/virtual_driver/win/virtual_driver_helpers.cc

Issue 6930019: Added resources. (Closed)
Patch Set: Dealing with git stupidity Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cloud_print/virtual_driver/win/virtual_driver_helpers.h ('k') | tools/grit/resource_ids » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 string16 GetPortMonitorDllName() {
38 if (IsSystem64Bit()) {
39 return string16(L"gcp_portmon64.dll");
40 } else {
41 return string16(L"gcp_portmon32.dll");
42 }
43 }
44
33 HRESULT GetPrinterDriverDir(FilePath* path) { 45 HRESULT GetPrinterDriverDir(FilePath* path) {
34 BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)]; 46 BYTE driver_dir_buffer[MAX_PATH * sizeof(wchar_t)];
35 DWORD needed = 0; 47 DWORD needed = 0;
36 if (!GetPrinterDriverDirectory(NULL, 48 if (!GetPrinterDriverDirectory(NULL,
37 NULL, 49 NULL,
38 1, 50 1,
39 driver_dir_buffer, 51 driver_dir_buffer,
40 MAX_PATH * sizeof(wchar_t), 52 MAX_PATH * sizeof(wchar_t),
41 &needed)) { 53 &needed)) {
42 // We could try to allocate a larger buffer if needed > MAX_PATH 54 // We could try to allocate a larger buffer if needed > MAX_PATH
43 // but that really shouldn't happen. 55 // but that really shouldn't happen.
44 return cloud_print::GetLastHResult(); 56 return cloud_print::GetLastHResult();
45 } 57 }
46 *path = FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer)); 58 *path = FilePath(reinterpret_cast<wchar_t*>(driver_dir_buffer));
47 59
48 // The XPS driver is a "Level 3" driver 60 // The XPS driver is a "Level 3" driver
49 *path = path->Append(L"3"); 61 *path = path->Append(L"3");
50 return S_OK; 62 return S_OK;
51 } 63 }
64
65 bool IsSystem64Bit() {
66 base::win::OSInfo::WindowsArchitecture arch =
67 base::win::OSInfo::GetInstance()->architecture();
68 return (arch == base::win::OSInfo::X64_ARCHITECTURE) ||
69 (arch == base::win::OSInfo::IA64_ARCHITECTURE);
52 } 70 }
53 71
72 string16 LoadLocalString(DWORD string_id) {
73 static wchar_t dummy = L'\0';
74 // We never expect strings longer than MAX_PATH characters.
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 CHECK_NE(0, count);
86 return string16(buffer);
87 }
88 }
89
OLDNEW
« no previous file with comments | « cloud_print/virtual_driver/win/virtual_driver_helpers.h ('k') | tools/grit/resource_ids » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698