DeletePrinter()
Posted: Sat Oct 21, 2006 2:53 pm
Hello all.
I'm trying to automatically delete a printer by the source below, but I always receive Error 5 and I don't find where's the error.
Do you see something wrong ?
Thanks,
Davide.
I'm trying to automatically delete a printer by the source below, but I always receive Error 5 and I don't find where's the error.
Do you see something wrong ?
Thanks,
Davide.
Code: Select all
#include "FiveWin.ch"
#include "Struct.ch"
// #include "WinSpool.h"
#define PRINTER_ACCESS_ADMINISTER 0x00000004
function DelPrn( cName )
Local Result:=.f.,oPrnDefaults,hDC
DEFAULT cName := "Test"
STRUCT oPrnDefaults
MEMBER pDatatype AS LPSTR
MEMBER pDevMode AS LPSTR // LPDEVMODE
MEMBER DesiredAccess AS DWORD // ACCESS_MASK
ENDSTRUCT
oPrnDefaults:DesiredAccess = PRINTER_ACCESS_ADMINISTER
IF ( ASCAN(aDevName(),{|x| Upper(x) == Upper(cName)}) >0 )
If OpenPrinter(cName , @hDC , oPrnDefaults:cBuffer )
If hDC # 0
Result := DelPrinter( hDC )
If !Result ; MsgAlert( 'DelPrn Error ' + Str( GetLastError() ) ) ; Endif
//
// --- Always receive Error 5 here !!! ---
//
ClosePrinter( hDC )
Endif
Endif
Endif
Return Result
//------------------------------------------------------------------------//
DLL32 FUNCTION ClosePrinter( pPrinter AS LONG ) AS BOOL PASCAL ;
FROM "ClosePrinterA" LIB "winspool.drv"
//------------------------------------------------------------------------//
DLL32 FUNCTION DelPrinter( pPrinter AS LONG ) AS BOOL PASCAL ;
FROM "DeletePrinter" LIB "winspool.drv"
//------------------------------------------------------------------------//
DLL32 FUNCTION OpenPrinter( pName AS LPSTR, @pPrinter AS LONG, pDef AS LPSTR ) ;
AS BOOL PASCAL ;
FROM "OpenPrinterA" LIB "winspool.drv"
//------------------------------------------------------------------------//