printing_info_win.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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. 4 5#ifndef PRINTING_BACKEND_PRINTING_INFO_WIN_H_ 6#define PRINTING_BACKEND_PRINTING_INFO_WIN_H_ 7 8#include <objidl.h> 9#include <winspool.h> 10 11#include "base/memory/scoped_ptr.h" 12#include "printing/printing_export.h" 13 14namespace printing { 15 16namespace internal { 17 18PRINTING_EXPORT uint8* GetDriverInfo(HANDLE printer, int level); 19PRINTING_EXPORT uint8* GetPrinterInfo(HANDLE printer, int level); 20 21// This class is designed to work with PRINTER_INFO_X structures 22// and calls GetPrinter internally with correctly allocated buffer. 23template <typename PrinterInfoType, int level> 24class PrinterInfo { 25 public: 26 bool Init(HANDLE printer) { 27 buffer_.reset(GetPrinterInfo(printer, level)); 28 return buffer_; 29 } 30 31 const PrinterInfoType* get() const { 32 return reinterpret_cast<const PrinterInfoType*>(buffer_.get()); 33 } 34 35 private: 36 scoped_ptr<uint8[]> buffer_; 37}; 38 39// This class is designed to work with DRIVER_INFO_X structures 40// and calls GetDriverInfo internally with correctly allocated buffer. 41template <typename DriverInfoType, int level> 42class DriverInfo { 43 public: 44 bool Init(HANDLE printer) { 45 buffer_.reset(GetDriverInfo(printer, level)); 46 return buffer_; 47 } 48 49 const DriverInfoType* get() const { 50 return reinterpret_cast<const DriverInfoType*>(buffer_.get()); 51 } 52 53 private: 54 scoped_ptr<uint8[]> buffer_; 55}; 56 57} // namespace internal 58 59typedef internal::PrinterInfo<PRINTER_INFO_2, 2> PrinterInfo2; 60typedef internal::PrinterInfo<PRINTER_INFO_5, 5> PrinterInfo5; 61 62typedef internal::DriverInfo<DRIVER_INFO_6, 6> DriverInfo6; 63 64} // namespace printing 65 66#endif // PRINTING_BACKEND_PRINTING_INFO_WIN_H_ 67