-
Notifications
You must be signed in to change notification settings - Fork 316
/
winspool.go
101 lines (84 loc) · 2.62 KB
/
winspool.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2010 The win Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package win
import (
"golang.org/x/sys/windows"
"syscall"
"unsafe"
)
// EnumPrinters flags
const (
PRINTER_ENUM_DEFAULT = 0x00000001
PRINTER_ENUM_LOCAL = 0x00000002
PRINTER_ENUM_CONNECTIONS = 0x00000004
PRINTER_ENUM_FAVORITE = 0x00000004
PRINTER_ENUM_NAME = 0x00000008
PRINTER_ENUM_REMOTE = 0x00000010
PRINTER_ENUM_SHARED = 0x00000020
PRINTER_ENUM_NETWORK = 0x00000040
)
type PRINTER_INFO_4 struct {
PPrinterName *uint16
PServerName *uint16
Attributes uint32
}
var (
// Library
libwinspool *windows.LazyDLL
// Functions
deviceCapabilities *windows.LazyProc
documentProperties *windows.LazyProc
enumPrinters *windows.LazyProc
getDefaultPrinter *windows.LazyProc
)
func init() {
// Library
libwinspool = windows.NewLazySystemDLL("winspool.drv")
// Functions
deviceCapabilities = libwinspool.NewProc("DeviceCapabilitiesW")
documentProperties = libwinspool.NewProc("DocumentPropertiesW")
enumPrinters = libwinspool.NewProc("EnumPrintersW")
getDefaultPrinter = libwinspool.NewProc("GetDefaultPrinterW")
}
func DeviceCapabilities(pDevice, pPort *uint16, fwCapability uint16, pOutput *uint16, pDevMode *DEVMODE) uint32 {
ret, _, _ := syscall.Syscall6(deviceCapabilities.Addr(), 5,
uintptr(unsafe.Pointer(pDevice)),
uintptr(unsafe.Pointer(pPort)),
uintptr(fwCapability),
uintptr(unsafe.Pointer(pOutput)),
uintptr(unsafe.Pointer(pDevMode)),
0)
return uint32(ret)
}
func DocumentProperties(hWnd HWND, hPrinter HANDLE, pDeviceName *uint16, pDevModeOutput, pDevModeInput *DEVMODE, fMode uint32) int32 {
ret, _, _ := syscall.Syscall6(documentProperties.Addr(), 6,
uintptr(hWnd),
uintptr(hPrinter),
uintptr(unsafe.Pointer(pDeviceName)),
uintptr(unsafe.Pointer(pDevModeOutput)),
uintptr(unsafe.Pointer(pDevModeInput)),
uintptr(fMode))
return int32(ret)
}
func EnumPrinters(Flags uint32, Name *uint16, Level uint32, pPrinterEnum *byte, cbBuf uint32, pcbNeeded, pcReturned *uint32) bool {
ret, _, _ := syscall.Syscall9(enumPrinters.Addr(), 7,
uintptr(Flags),
uintptr(unsafe.Pointer(Name)),
uintptr(Level),
uintptr(unsafe.Pointer(pPrinterEnum)),
uintptr(cbBuf),
uintptr(unsafe.Pointer(pcbNeeded)),
uintptr(unsafe.Pointer(pcReturned)),
0,
0)
return ret != 0
}
func GetDefaultPrinter(pszBuffer *uint16, pcchBuffer *uint32) bool {
ret, _, _ := syscall.Syscall(getDefaultPrinter.Addr(), 2,
uintptr(unsafe.Pointer(pszBuffer)),
uintptr(unsafe.Pointer(pcchBuffer)),
0)
return ret != 0
}