forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprinting_info_win.cc
49 lines (40 loc) · 1.31 KB
/
printing_info_win.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
// 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 "printing/backend/printing_info_win.h"
#include <stdint.h>
#include "base/logging.h"
namespace printing {
namespace internal {
uint8_t* GetDriverInfo(HANDLE printer, int level) {
DWORD size = 0;
::GetPrinterDriver(printer, NULL, level, NULL, 0, &size);
if (size == 0) {
return NULL;
}
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]);
memset(buffer.get(), 0, size);
if (!::GetPrinterDriver(printer, NULL, level, buffer.get(), size, &size)) {
return NULL;
}
return buffer.release();
}
uint8_t* GetPrinterInfo(HANDLE printer, int level) {
DWORD size = 0;
::GetPrinter(printer, level, NULL, 0, &size);
if (size == 0) {
LOG(WARNING) << "Failed to get size of PRINTER_INFO_" << level
<< ", error = " << GetLastError();
return NULL;
}
std::unique_ptr<uint8_t[]> buffer(new uint8_t[size]);
memset(buffer.get(), 0, size);
if (!::GetPrinter(printer, level, buffer.get(), size, &size)) {
LOG(WARNING) << "Failed to get PRINTER_INFO_" << level
<< ", error = " << GetLastError();
return NULL;
}
return buffer.release();
}
} // namespace internal
} // namespace printing