Jump to content
Fivewin Brasil

Erro quando a impressora não existe


oribeiro

Recommended Posts

Pessoal,

Vejam esse erro:

Aplicacao
=========
Descricao do erro.: Alerta GPFHANDLER/0 EXCEPTION_ACCESS_VIOLATION - Tentativa de ler/escrever onde o usuário não tem acesso.: GPFHANDLER
Args:
Args:
[ 1] = C EXCEPTION_ACCESS_VIOLATION - Tentativa de ler/escrever onde o usuário não tem acesso.
[ 2] = O EXCEPTION_ACCESS_VIOLATION - Tentativa de ler/escrever onde o usuário não tem acesso.
[ 3] = N EXCEPTION_ACCESS_VIOLATION - Tentativa de ler/escrever onde o usuário não tem acesso.


Esse erro ocorre quando o usuário tenta imprimir numa impressora que está na fila da estação, mas que não existe mais no servidor (foi removida).

Exemplo:

Computador-A cede o compartilhamento da impressora HP

Computador-B compartilha a impressora \\Computador-A\HP

Computador-A desinstala a impressora HP

Computador-B continua com ela na lista, seleciona ela no sistema e tenta imprimir.

Como resolvo isso? Há uma forma de eu identificar que a impressora não está ativa e evitar esse erro?

Aguardo, obrigado.

Link to comment
Share on other sites

João,

As minhas funções de verificação da impressora são essas:

Mais ela não detecta se a impressora está ativa ou não.

********************************************************************************************
FUNCTION PrintSetup(lTela,cTitulo) // Confirma impressão e configura impressora
********************************************************************************************
   Local   oDlg, oPr, oGr, cPr
   Local   vOk     := .F.
   Default lTela   := .F.
   Default cTitulo := "(OASyS) Configuração da Impressão"
   // SEMPRE verificar se tem impressora, senão dá erro GPF em OAGetName() e OAGetPort() //
   vOk := OAIsPrinter( lTela )
   // Se for para impressão direta, abre uma JANELA para o usuário selecionar a impressora //
   IF vOk //.AND. !lTela
      cPr := OAGetName()+" em "+OAGetPort()
      DEFINE DIALOG oDlg RESOURCE "IMPRSETUP" TITLE cTitulo FONT oFontSay //TRANSPARENT
      REDEFINE ICON ID ID_BITMAP OF oDlg RESOURCE "IMPRES2"
      REDEFINE SAY PROMPT "Confirme a "+iif(lTela,"Visualização","Impressão") ID 1100 OF oDlg ;
               FONT oFontBig COLOR CLR_BLUE
      REDEFINE GROUP oGr ID 125 OF oDlg PROMPT iif(lTela,"A visualização utilizará o driver da impressora:","A impressão será enviada para a impressora:") FONT oFontGet
      REDEFINE GET   oPr VAR cPr ID 183 OF oDlg WHEN .F. FONT oFontGet
      REDEFINE ButtonBmp ID 180 OF oDlg                            ;
               PROMPT "C&ontinua"  BITMAP "B_OK1";
               ACTION (vOk:=OAIsPrinter(lTela), iif(vOk, oDlg:End(),.F.))
      REDEFINE ButtonBmp ID 181 OF oDlg                            ;
               PROMPT "Confi&gura" BITMAP "B_CONFIG1";
               ACTION (oaPrinterSetup(), cPr:=OAGetName()+" em "+OAGetPort(), oPr:Refresh())
      REDEFINE ButtonBmp ID 182 OF oDlg                            ;
               PROMPT "&Cancela"   BITMAP "B_CANCEL1";
               ACTION (vOk:=.F., oDlg:End())
      ACTIVATE DIALOG oDlg CENTERED RESIZE16
   ENDIF
Return( vOk )

********************************************************************************************
FUNCTION OAIsPrinter( lTela, lMsg ) // Verifica se a impressora está instalada
********************************************************************************************
/*
   // ISPRINTER() só funciona para impressora conectada na LPTx do computador, senão dá .F.  //
   If !IsPrinter()
      if lMsg
         MsgStop("Não estou conseguindo me conectar à sua impressora para iniciar o processo de "+iif(lTela,"visualização.","impressão.") + CRLF + CRLF + ;
                 "Por favor, verifique se a impressora está instalada corretamente no seu MS-Windows." + CRLF + CRLF + ;
                 "É necessário ter pelo menos uma impressora configurada no MS-Windows para "+iif(lTela,"visualizar","imprimir")+" relatórios no sistema.",;
                 "(OASyS) Relatórios - ATENÇÃO: Verifique a impressora.")
      endif
      lRet := .F.
   EndIf
   // Verifica se tem impressora instalada no MS-Windows -> Substitui a função IsPrinter()   //
   if ComDlgXErr() != 0 // Essa função está no Printer.c e é usada na classe Printer.prg
      if lMsg
         MsgStop("Não estou conseguindo me conectar à sua impressora para iniciar o processo de "+iif(lTela,"visualização.","impressão.") + CRLF + CRLF + ;
                 "Por favor, verifique se a impressora está instalada corretamente no seu MS-Windows." + CRLF + CRLF + ;
                 "É necessário ter pelo menos uma impressora configurada no MS-Windows para "+iif(lTela,"visualizar","imprimir")+" relatórios no sistema.",;
                 "(OASyS) Relatórios - ATENÇÃO: Verifique a impressora.")
      endif
      lRet := .F.
   endif
*/
   Local   oPrn
   Local   lRet  := .T.
   Default lTela := .F.
   Default lMsg  := .T.
   // Se não tem nenhuma impressora selecionada, abre a tela de seleção de impressora //
   if Empty( nTemImpr )
      oaPrinterSetup()
   endif
   // Verifica se tem impressora instalada no MS-Windows -> Substitui a função IsPrinter()   //
   // Na visualização essa rotina não é necessária porque o FWH já checa se tem impressoras. //
   PRINT oPrn
      if !Empty( oPrn:hDC )
         oPrn:SetPage( 9 )          // 1=Carta e 9=A4
         oPrn:SetSize( 2100, 2970 ) // Tamanho: A4 = 210mm x 297mm
         oPrn:SetPortrait()         // Sentido da impressão
      else
         if lMsg
            MsgStop("Não estou conseguindo me conectar à sua impressora para iniciar o processo de "+iif(lTela,"visualização.","impressão.") + CRLF + CRLF + ;
                    "Por favor, verifique se a impressora está instalada corretamente no seu MS-Windows." + CRLF + CRLF + ;
                    "É necessário ter pelo menos uma impressora configurada no MS-Windows para "+iif(lTela,"visualizar","imprimir")+" relatórios no sistema.",;
                    "(OASyS) Relatórios - ATENÇÃO: Verifique a impressora.")
         endif
         lRet := .F.
      endif
   ENDPRINT
Return( lRet )

********************************************************************************************
FUNCTION OAGetName() // PRNGETNAME() dá erro GPF quando não tem impressora instalada
********************************************************************************************
   if !Empty( nTemImpr )
      Return( PrnGetName() )
   endif
Return("Impressora Padrão")

********************************************************************************************
FUNCTION OAGetPort() // PRNGETPORT() dá erro GPF quando não tem impressora instalada
********************************************************************************************
   if !Empty( nTemImpr )
      Return( PrnGetPort() )
   endif
Return("LPTx")

********************************************************************************************
FUNCTION oaPrinterSetup()           // Sem essa função, o FWH respeita a seleção apenas para o próximo relatório, voltando depois para o padrão do Windows.
********************************************************************************************
// SetDefaultPrinter( OAGetName() ) // Coloca a impressora selecionada como Default do Windows (( Não usar porque muda de toda a rede )) // ou // SetPrintDefault( OAGetName() )
// GetPrintDC( GetActiveWindow() )  // Abre a tela para a seleção da impressora
// PrinterSetup()                   // Abre a tela para a seleção da impressora -> Era assim até 29/09/2014 (mudei para remover o botão [REDE] que abria caminho para o usuário mexer nos arquivos).
   GetPrintDC()                     // Abre a tela para a seleção da impressora
   nTemImpr := iif(!Empty( nTemImpr ), nTemImpr, GetPrintDefault( GetActiveWindow() )) // Define a impressora padrão para não dar problema com USB //
   pImprDef := OAGetName()          // Grava a última impressora selecionada pelo usuário
Return nil

Link to comment
Share on other sites

ou:



// FiveWin labels!!! done with FiveWin !!!

#include "FiveWin.ch"

#define HORZ_LABELS 3
#define VERT_LABELS 6

//----------------------------------------------------------------------------//

function Main()

local oWnd

SET _3DLOOK ON

DEFINE WINDOW oWnd TITLE "FiveWin Labels"

@ 2, 2 BUTTON "&Labels" SIZE 120, 25 OF oWnd ;
ACTION GenerateLabels()

ACTIVATE WINDOW oWnd

return nil

//----------------------------------------------------------------------------//

function GenerateLabels()

local oPrinter, oFont, cPrint
local nWidth, nHeight, nMargin, nLblWidth, nLblHeight
local n, m, nRow := 5 , nCol := 5

// Obrigue a abrir a pasta de impressoras...
PRINTER oPrinter FROM USER // open oPrint object with the printer

IF EMPTY( oPrinter:hDC )

MsgStop( "Atenção Usuário: " +CRLF+ ;
"Você Não Escolheu Uma Impressora " +CRLF+ ;
"................................ ", ;
"Impressora Não Escolhida " )

oPrinter:End()

RETURN NIL

ENDIF

// Ou verifique se a impressora e uma da lista - crie a lista:
cPrint := oPrinter:GETMODEL() // PEGA O NOME DA IMPRESSORA.
oPrinter:End()

? cPrint

// Se o Nome da Impressora For uma destas - crie a lista.
// ou force a abrir dispositivos de impressoras.
IF cPrint == [PDFCreator] .OR. ;
cPrint == [BroadGun pdfMachine] .OR. ;
cPrint == [pdfFactory] .OR. ;
cPrint == [pdfFactory Pro] .OR. ;
cPrint == [Bullzip PDF Printer] .OR. ;
cPrint == [CutePDF Writer] .OR. ;
cPrint == [Expert PDF Pro] .OR. ;
cPrint == [doPDF v7]

// nada a fazer, deixa imprimir Pois esta na lista de impressoras.

ELSE // NAO E NENHUMA DAS IMPRESSORAS.
// ? "mensagem se quiser..."
RETURN NIL
ENDIF

/* // SE NAO QUISER COMO ACIMA, FORCE ASSIM.
PRINTER oPrinter FROM USER ;
NAME "Fivewin Labels" PREVIEW
*/

PRINTER oPrinter NAME "Fivewin Labels" PREVIEW

DEFINE FONT oFont NAME "Times New Roman" SIZE 0, -14 ;
OF oPrinter

nLblWidth = oPrinter:nHorzRes() / HORZ_LABELS
nLblHeight = oPrinter:nVertRes() / VERT_LABELS
nMargin = Int( oPrinter:nLogPixelX() * 0.2 )

CursorWait()

oPrinter:StartPage()

for n = 1 to VERT_LABELS
for m = 1 to HORZ_LABELS
oPrinter:Box( nRow, nCol, nRow + nLblHeight - 20, nCol + nLblWidth - 50 )
oPrinter:SayBitmap( nRow + nLblHeight / 5 - 150,;
nCol + ( nLblWidth / 2 ) - 300,;
"..\bitmaps\FiveWin.bmp", nLblWidth / 3,;
nLblHeight / 1.8 )
nCol += nLblWidth
next
nRow += nLblHeight
nCol = 5
next

oPrinter:EndPage()

CursorArrow()

oPrinter:Preview()
oFont:End()

return nil

//----------------------------------------------------------------------------//


Link to comment
Share on other sites

Controle as impressoras...



#define PRINTER_STATUS_OK 0
#define PRINTER_STATUS_PAUSED 1
#define PRINTER_STATUS_ERROR 2
#define PRINTER_STATUS_PENDING_DELETION 4
#define PRINTER_STATUS_PAPER_JAM 8
#define PRINTER_STATUS_PAPER_OUT 16
#define PRINTER_STATUS_MANUAL_FEED 32
#define PRINTER_STATUS_PAPER_PROBLEM 64
#define PRINTER_STATUS_OFFLINE 128
#define PRINTER_STATUS_IO_ACTIVE 256
#define PRINTER_STATUS_BUSY 512
#define PRINTER_STATUS_PRINTING 1024
#define PRINTER_STATUS_OUTPUT_BIN_FULL 2048
#define PRINTER_STATUS_NOT_AVAILABLE 4096
#define PRINTER_STATUS_WAITING 8192
#define PRINTER_STATUS_PROCESSING 16384
#define PRINTER_STATUS_INITIALIZING 32768
#define PRINTER_STATUS_WARMING_UP 65536
#define PRINTER_STATUS_TONER_LOW 131072
#define PRINTER_STATUS_NO_TONER 262144
#define PRINTER_STATUS_PAGE_PUNT 524288
#define PRINTER_STATUS_USER_INTERVENTION 1048576
#define PRINTER_STATUS_OUT_OF_MEMORY 2097152
#define PRINTER_STATUS_DOOR_OPEN 4194304
#define PRINTER_STATUS_SERVER_UNKNOWN 8388608
#define PRINTER_STATUS_POWER_SAVE 16777216

function Main()

local nStatus := PrnStatus( "LPT1:" )

MsgInfo( nStatus )

return nil


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...