Page 1 of 1

No Printers installed

Posted: Mon May 04, 2009 4:09 pm
by StefanHaupt
Dear friends,

I have a problem printing reports on my notebook with Vista. I get the message "There are no printers installed. Please exit this ...".

In fact I have printers installed and there is also a default printer defined.

I found the reason for this error is in these lines in printer.prg

Code: Select all

.....
    elseif cModel == nil
      ::hDC  := GetPrintDefault( GetActiveWindow() )
      if ::hDC != 0
        cModel = ::GetModel() + "," + ::GetDriver() + "," + ::GetPort()
      endif
.....
  if ::hDC != 0
      aOffset    = PrnOffset( ::hDC )
      ::nXOffset = aOffset[ 1 ]
      ::nYOffset = aOffset[ 2 ]
      ::nOrient  = ::GetOrientation()
   elseif ComDlgXErr() != 0  // PDERR_NODEFAULTPRN = 0x1008 (4104)
      MsgStop( "There are no printers installed!"  + CRLF + ;
               "Please exit this application and install a printer." )
      ::nXOffset = 0
      ::nYOffset = 0
....
::lUser is .f., I don´t open a common dialog box

ComDlgXErr() returns 4104 (PDERR_NODEFAULTPRN), although GetPrintDefault() returns a correct handle and GetModel() returns the correct printer name of the default printer.

Why does ComDlgXErr() return an error code ?

Does anyone noticed this behavior ?

Re: No Printers installed

Posted: Tue May 05, 2009 9:14 pm
by Jonathan Hodder
I recall having this problem a long time ago.
I think my problem was related to GetActiveWindow().
It was a one off program so I did not persue the problem.
I think I solved it by passing the main window through as
a static to replace the DC ie ... GetPrintDefault( n?? ).
Not good but it worked and thats all I needed.

Maybe this helps

JH

Re: No Printers installed

Posted: Wed May 06, 2009 11:08 am
by StefanHaupt
Jonathan,

thanks for your hint, but finally I found the problem.

I called the report with REPORT oReport .... TO PRINTER and than I tried to define the device with oReport:oDevice := TPrinter ():New(...), where the report should be printed.

I found, that TPrinter ():New(...) was called twice, first in the report class and the second time from my function. This was working with XP, but with Vista the second call caused the error.

So my solution is now to define the device first and than call the report class.

Code: Select all

oDevice := TPrinter():New(...)
REPORT oReport .... TO DEVICE oDevice