Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Define argtypes and restype for functions called via CTypes
  • Loading branch information
CristiFati committed Dec 3, 2021
commit a0f19d4df002a9dd0b8b137fa452d77b57ef8921
25 changes: 23 additions & 2 deletions recipes/Python/305690_Enumerate_printer_job/recipe-305690.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time
from ctypes import *
from ctypes import wintypes as wt


"""
This script enumerates printer jobs from a specified default printer. This information includes Jobid, Document name,
Expand All @@ -18,8 +20,27 @@
license GPL

"""

LPPRINTER_DEFAULTS = wt.LPVOID

ws = WinDLL("winspool.drv")

ws.ClosePrinter.argtypes = (wt.HANDLE,)
ws.ClosePrinter.restype = wt.BOOL

ws.EnumJobsA.argtypes = (wt.HANDLE, wt.DWORD, wt.DWORD, wt.DWORD, wt.LPBYTE, wt.DWORD, wt.LPDWORD, wt.LPDWORD)
ws.EnumJobsA.restype = wt.BOOL

ws.GetDefaultPrinterA.argtypes = (wt.LPSTR, wt.LPDWORD)
ws.GetDefaultPrinterA.restype = wt.BOOL

ws.OpenPrinterA.argtypes = (wt.LPSTR, POINTER(wt.HANDLE), LPPRINTER_DEFAULTS)
ws.OpenPrinterA.restype = wt.BOOL

ws.ReadPrinter.argtypes = (wt.HANDLE, wt.LPVOID, wt.DWORD, wt.LPDWORD)
ws.ReadPrinter.restype = wt.BOOL


#-- Job Status meaning
JOB_STATUS_PAUSED = 0x00000001
JOB_STATUS_ERROR = 0x00000002
Expand Down Expand Up @@ -130,7 +151,7 @@ def ReadPrinterData(self, hPrinter):

def GetDefaultPrinter(self):
#-- Get the default printer
plen = c_long()
plen = wt.DWORD()
ret = ws.GetDefaultPrinterA(None, byref(plen))
pname = c_buffer(plen.value)
ret = ws.GetDefaultPrinterA(pname, byref(plen))
Expand All @@ -140,7 +161,7 @@ def OpenPrinter(self, prtname = None):
#-- Let open our printer
if prtname == None:
self.prtname = self.GetDefaultPrinter()
self.handle = c_ulong()
self.handle = wt.HANDLE()
ret = ws.OpenPrinterA(self.prtname, byref(self.handle), None)
return self.handle

Expand Down