Anyone have a command to cancel all print jobs?
I do a lot of background printing and would
like to cancel jobs from within a program.
I do a lot of background printing and would
like to cancel jobs from within a program.
Public Declare Function SetPrinter Lib "winspool.drv" Alias "SetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Byte, ByVal Command As Long) As Long Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, pDefault As Any) As Long Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Public Const PRINTER_CONTROL_PURGE = 3 'DeletePrinterJob Sub DeletePrinterJob() Dim PrinterName$ Dim ret& Dim hPrinter& PrinterName = Printer.DeviceName ret = OpenPrinter(PrinterName, hPrinter, 0) ret = SetPrinter(hPrinter, 0, vbNull, PRINTER_CONTROL_PURGE) ret = ClosePrinter(hPrinter) End Sub
'Any help on getting a routine for cancelling printer 'would be appreicated. 'PrinterName = Printer.DeviceName 'where does that come from? 'Anyway this compiles, but doesn't do anything. 'What types should be used? #COMPILE EXE #DIM ALL #REGISTER NONE ' size of a device name string %CCHDEVICENAME = 32 ' size of a form name string %CCHFORMNAME = 32 %NULL = 0 TYPE DEVMODE dmDeviceName AS ASCIIZ * %CCHDEVICENAME dmSpecVersion AS WORD dmDriverVersion AS WORD dmSize AS WORD dmDriverExtra AS WORD dmFields AS DWORD dmOrientation AS INTEGER dmPaperSize AS INTEGER dmPaperLength AS INTEGER dmPaperWidth AS INTEGER dmScale AS INTEGER dmCopies AS INTEGER dmDefaultSource AS INTEGER dmPrintQuality AS INTEGER dmColor AS INTEGER dmDuplex AS INTEGER dmYResolution AS INTEGER dmTTOption AS INTEGER dmCollate AS INTEGER dmFormName AS ASCIIZ * %CCHFORMNAME dmLogPixels AS WORD dmBitsPerPel AS DWORD dmPelsWidth AS DWORD dmPelsHeight AS DWORD dmDisplayFlags AS DWORD dmDisplayFrequency AS DWORD dmICMMethod AS DWORD dmICMIntent AS DWORD dmMediaType AS DWORD dmDitherType AS DWORD dmICCManufacturer AS DWORD dmICCModel AS DWORD ' dmPanningWidth AS DWORD ' this & below apply if WINVER >= &H500 ' dmPanningHeight AS DWORD ' ...or if _WIN32_WINNT >= &H400 END TYPE TYPE ACL AclRevision AS BYTE Sbz1 AS BYTE AclSize AS WORD AceCount AS WORD Sbz2 AS WORD END TYPE TYPE SECURITY_DESCRIPTOR Revision AS BYTE Sbz1 AS BYTE nControl AS WORD Owner AS LONG Group AS LONG Sacl AS ACL PTR Dacl AS ACL PTR END TYPE TYPE SYSTEMTIME wYear AS INTEGER wMonth AS INTEGER wDayOfWeek AS INTEGER wDay AS INTEGER wHour AS INTEGER wMinute AS INTEGER wSecond AS INTEGER wMilliseconds AS INTEGER END TYPE TYPE JOB_INFO_2 JobId AS DWORD pPrinterName AS ASCIIZ PTR pMachineName AS ASCIIZ PTR pUserName AS ASCIIZ PTR pDocument AS ASCIIZ PTR pNotifyName AS ASCIIZ PTR pDatatype AS ASCIIZ PTR pPrintProcessor AS ASCIIZ PTR pParameters AS ASCIIZ PTR pDriverName AS ASCIIZ PTR pDevMode AS DEVMODE PTR pStatus AS ASCIIZ PTR pSecurityDescriptor AS SECURITY_DESCRIPTOR PTR STATUS AS DWORD Priority AS DWORD Position AS DWORD StartTime AS DWORD UntilTime AS DWORD TotalPages AS DWORD nSize AS DWORD Submitted AS SYSTEMTIME time AS DWORD PagesPrinted AS DWORD END TYPE TYPE PRINTER_DEFAULTS pDatatype AS ASCIIZ PTR pDevMode AS DEVMODE PTR DesiredAccess AS DWORD END TYPE DECLARE FUNCTION OpenPrinter LIB "WINSPOOL.DRV" ALIAS "OpenPrinterA" _ (pPrinterName AS ASCIIZ, _ phPrinter AS LONG, _ pDefault AS PRINTER_DEFAULTS) AS LONG DECLARE FUNCTION SetPrinter LIB "WINSPOOL.DRV" ALIAS "SetPrinterA" _ (BYVAL hPrinter AS LONG, _ BYVAL Level AS LONG, _ pPrinter AS BYTE, _ BYVAL Command AS LONG) AS LONG DECLARE FUNCTION ClosePrinter LIB "WINSPOOL.DRV" ALIAS "ClosePrinter" _ (BYVAL hPrinter AS LONG) AS LONG FUNCTION PBMAIN AS LONG CALL DeletePrinterJob END FUNCTION SUB DeletePrinterJob() 'does printer name need to be passed here? DIM Command_Purge& Command_Purge& = 3 ' DIM pPrinterName AS ASCIIZ * 64 DIM ret& DIM phPrinter AS LONG 'Does this need PTR? DIM Level AS LONG DIM hPrinter AS LONG DIM pDefaults AS PRINTER_DEFAULTS ret = OpenPrinter(pPrinterName, _ phPrinter, _ 'should this be a pointer? pDefaults) ret = SetPrinter(hPrinter&, _ Level&, _ %Null, _ Command_PURGE&) ret = ClosePrinter(hPrinter&) 'does this come from setprinter? END SUB
The definition in win32api.hlp. LPTSTR pPrinterName //address of printer or server name Points to a null-terminated string Points to a variable that receives the handle Points to a Printer_Defaults Doesn't this mean pointers? Declarations in win32api.inc: pPrinterName AS ASCIIZ, _ 'this is not a pointer phPrinter AS LONG, _ 'where is the pointer? pDefault AS PRINTER_DEFAULTS) AS LONG Where are the pointers defined in the declaration file? This is why I have trouble using the .HLP file. When it uses points to doesn't mean pointer?
#Compile Exe #Register None #Dim All #Include "Win32Api.Inc" Function PbMain Dim PrinterName As Asciiz * 256, hPrinter As Long GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName, SizeOf(PrinterName) PrinterName = Left$(PrinterName$, Instr(PrinterName, ",") - 1) OpenPrinter PrinterName, hPrinter, ByVal 0 SetPrinter hPrinter, 0, ByVal 0, %PRINTER_CONTROL_PURGE ClosePrinter hPrinter End Function
BOOL OpenPrinter( LPTSTR pPrinterName, // address of printer or server name LPHANDLE phPrinter, // address of printer or server handle LPPRINTER_DEFAULTS pDefault // address of printer defaults structure );
DIM myString as ASCIIZ * 120 DIM myPTR as LONG DIM myStringPtr as ASCIIZ PTR myString = "MIKE" myPTR = VARPTR(myString) You obviously know that myString holds "MIKE" and that myPTR holds the address or pointer to myString.. PRINT myString prints MIKE PRINT myPTR prints some numerical number (i.e. the address) myStringPtr = VARPTR(myString) PRINT @myStringPtr prints MIKE PRINT myStringPtr prints the SAME numerial number as myPTR above (i.e. the address of myString)
'The code below works fine as long as #DEBUG ERROR ON 'is used. Anyone know why it is needed? 'Otherwise I sometimes receive a GPF in 'Kernel32 017f;bff719fb #DEBUG ERROR ON #COMPILE EXE #REGISTER NONE #DIM ALL #INCLUDE "Win32Api.Inc" FUNCTION PBMAIN CALL CancelPrintJob END FUNCTION SUB CancelPrintJob DIM LineNumber AS LONG ON ERROR GOTO CancelPrintJobError LineNumber = 10 DIM PrinterName AS ASCIIZ * 256, hPrinter AS LONG LineNumber = 20 GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName, SIZEOF(PrinterName) LineNumber = 30 PrinterName = LEFT$(PrinterName$, INSTR(PrinterName, ",") - 1) LineNumber = 40 OpenPrinter PrinterName, hPrinter, BYVAL 0 LineNumber = 50 SetPrinter hPrinter, 0, BYVAL 0, %PRINTER_CONTROL_PURGE ExitCancelPrintJob: LineNumber = 60 ClosePrinter hPrinter EXIT SUB CancelPrintJobError: MSGBOX "Error number" + STR$(ERR)+ " in Doty - CancelPrintJob at line "+STR$(ERR) RESUME ExitCancelPrintJob END SUB
Call SetPrinter(hPrinter&, 5, [b]BYVAL VARPTR(1stElementOfAnArrayOfPrinterInfo5structures(0)[/b], PrinterState&)
'Lance, ' Rewrote the thing and it no longer abends. ' Problem is, it now doesn't do anything. ' Also tried AbortPrinter(hPrinter) unsuccessfully. ' Help #DEBUG ERROR ON #COMPILE EXE #REGISTER NONE #DIM ALL #INCLUDE "Win32Api.Inc" TYPE PRINTER_INFO_5 pPrinterName AS ASCIIZ PTR pPortName AS ASCIIZ PTR Attributes AS DWORD DeviceNotSelected AS DWORD TransmissionRetryTimeout AS DWORD END TYPE FUNCTION IsWin95() EXPORT AS LONG LOCAL vi AS OSVERSIONINFO vi.dwOsVersionInfoSize = SIZEOF(vi) GetVersionEx vi FUNCTION = (vi.dwPlatformId = %VER_PLATFORM_WIN32_WINDOWS) END FUNCTION FUNCTION PBMAIN CALL CancelPrintJob END FUNCTION SUB CancelPrintJob DIM ret AS LONG DIM Level AS LONG DIM Needed AS LONG DIM Returned AS LONG DIM hPrinter AS LONG IF IsWin95 THEN Level = 5 ELSE Level = 4 'Printer structure to use IF Level = 5 THEN 'First call to see how big WINDOWS 95 printer_info_5 structure CALL EnumPrinters(%PRINTER_ENUM_LOCAL, _ BYVAL 0, _ BYVAL Level, _ BYVAL %NULL, _ BYVAL 0, _ needed&, _ 'Size of structure in bytes returned&) DIM PI5(0) AS PRINTER_INFO_5 REDIM PI5(needed& \ SIZEOF(PI5(0))) CALL EnumPrinters(%PRINTER_ENUM_LOCAL, _ BYVAL 0, _ BYVAL Level, _ BYVAL VARPTR(PI5(0)), _ needed&, _ needed&, _ returned&) 'Number of printers 'FOR Element = 0 TO Returned& - 1 ' EntireString = EntireString + PI5(Element)[email protected]+"," 'NEXT ELSE ' Windows NT 'First call to see how big WINDOWS NT printer_info_4 structure CALL EnumPrinters(%PRINTER_ENUM_CONNECTIONS, _ BYVAL 0, _ BYVAL Level, _ BYVAL %NULL, _ BYVAL 0, _ needed&, _ 'Size of structure returned in needed& returned&) DIM PI4(0) AS PRINTER_INFO_4 REDIM PI4(needed& \ SIZEOF(PI4(0))) CALL EnumPrinters(%PRINTER_ENUM_CONNECTIONS, _ 'Use CONNECTIONS with NT BYVAL 0, _ BYVAL Level, _ BYVAL VARPTR(PI4(0)), _ needed&, _ needed&, _ returned&) 'Number of printers 'FOR Element = 0 TO Returned& - 1 ' EntireString = EntireString + PI4(Element)[email protected]+"," 'NEXT END IF 'GetPrinterNames = LEFT$(EntireString,LEN(EntireString)-1) 'DIM PrinterArray(1) AS Printer_INFO_5 'Lance, is this correct? DIM LineNumber AS LONG ON ERROR GOTO CancelPrintJobError LineNumber = 10 'DIM PrinterName AS ASCIIZ * 256, hPrinter AS LONG 'LineNumber = 20 'GetProfileString "WINDOWS", "DEVICE", ",,,", PrinterName, SIZEOF(PrinterName) 'LineNumber = 30 'PrinterName = LEFT$(PrinterName$, INSTR(PrinterName, ",") - 1) 'LineNumber = 40 IF Level = 5 THEN MSGBOX (PI5(0)[email protected]) 'Printer_info5 ret = OpenPrinter (PI5(0)[email protected], hPrinter, BYVAL %NULL) MSGBOX "Open printer "+STR$(ret) + "hPrinter = "+ STR$(hPrinter) CALL AbortPrinter(hPrinter) 'CALL SetPrinter (hPrinter&, _ ' Level, _ ' BYVAL VARPTR(PI5(0)), _ 'Lance is this correct? ' %PRINTER_CONTROL_PURGE) ' 'BYVAL VARPTR(1stElementOfAnArrayOfPrinterInfo5structures(0), _ ELSE MSGBOX (Pi4(0)[email protected]) ret = OpenPrinter (PI4(0)[email protected], hPrinter, BYVAL %NULL) 'Printer_Info4 MSGBOX "OpenPrinter "+STR$(ret)+ " hPrinter ="+STR$(hPrinter) CALL AbortPrinter(hPrinter) 'CALL SetPrinter (hPrinter&, _ ' Level, _ ' BYVAL VARPTR(PI4(0)), _ 'Lance is this correct? ' %PRINTER_CONTROL_PURGE) ' 'BYVAL VARPTR(1stElementOfAnArrayOfPrinterInfo5structures(0), _ END IF ExitCancelPrintJob: ClosePrinter hPrinter EXIT SUB CancelPrintJobError: MSGBOX "Error number" + STR$(ERR)+ " in Doty - CancelPrintJob at line "+STR$(ERR) RESUME ExitCancelPrintJob END SUB
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment