"No Default Printer" message on Windows 7 64-bit

"No Default Printer" message on Windows 7 64-bit

Postby hua » Fri Apr 30, 2010 6:50 am

One of our user uses Windows 7 64-bit. I suspect "No Default Printer" happens either at PrinterSetup() or oPrn:GetModel(). Anyone know any solution? It's fairly urgent. Already 2 of our users experienced this. The other user was running from a Windows Server 2008 64-bit.

TIA
Last edited by hua on Tue Jun 29, 2010 9:47 am, edited 1 time in total.
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit (Urgent)

Postby StefanHaupt » Fri Apr 30, 2010 7:29 am

Hua,

did you try the xHarbour built-in function GetDefaultPrinter () ? It´s working fine here with Win7 64bit.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: "No Default Printer" message on Windows 7 64-bit (Urgent)

Postby hua » Fri Apr 30, 2010 7:55 am

Thanks Stefan. I can't find GetDefaultPrinter() in the source but I did find GetPrintDefault(). I assume that's the one you meant?

Unfortunately, it doesn't address the logic that I want to implement. See, as a feature, in our program we allow user to select a printer and the program will later on always print to it without disturbing the setting of which printer is set to default in the control panel. This is the code that does the part of selecting and memorizing the printer name:

Code: Select all  Expand view

function ud_PrinterSetup()
 local cPrn
 PrinterSetup() // show printer selection dialog
 cPrn := trim(ud_PrnGetName()) //obtain the name of the printer selected just now
 if zPrinter != cPrn // zPrinter is a public var holding the name of the printer for every printout routine to use
    zPrinter := cPrn
    memowrit(set(_SET_DEFAULT)+"\default.prn", zPrinter)
 endif
return nil

function ud_PrnGetName()
 local cret, oprn
 PRINTER oPrn
 cRet := oPrn:getmodel()
 endprint
return cret
 
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit (Urgent)

Postby hua » Fri Apr 30, 2010 8:18 am

Just tried to substitute my ud_PrnGetName() with GetDefaultPrinter(). Seems GetDefaultPrinter() returns a numeric value instead of a printer name. That kinda makes it hard for me to know which printer was actually selected. It's unfortunate that my office doesn't have a Win7 64-bit. Makes it difficult for me to test any hypothesis that I might come up with
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit (Urgent)

Postby Richard Chidiak » Fri Apr 30, 2010 8:22 am

Hua

This is the function i use for printing

It works ok on windows 7 64 bits

HTH

Richard

[code][


#define DMPAPER_A4 9 // A4 210 x 297 mm

FUNCTION GETOPRN(OPRN)
LOCAL AIMPRI := {}, ;
LCRE := .F., ;
CMODEL

LOCAL cIniFile := INILOGI()

AIMPRI := GETIMPRI(@AIMPRI)

IF LEN(AIMPRI) = 1
OPRN := TPrinter():New(LOGINOM() + " Impression", .F. , .T. , AIMPRI[1] , .T. )
LCRE := .T.
ELSE
IF GetPvProfString("USER","PRINTDEF",,CINIFile ) = "O"
IF FILE("CAISSE.DBF")
cMODEL := GetProfString( "windows", "device" , "" ) // CHIDIAL
OPRN := TPrinter():New(LOGINOM() + " Impression", .F. , .T.,CMODEL, .T. )
ELSE
OPRN := TPrinter():New(LOGINOM() + " Impression", .F. , .T., , .T. )
ENDIF
LCRE := .T.
ENDIF
ENDIF

IF ! LCRE
MsgRun( "Sélection Imprimante en cours...", "Veuillez Patienter", ;
{ || SELIMPRI(@OPRN) } )
ENDIF

IF oPrn:hDC = 0
RETURN(.F.)
ENDIF
oPrn:SetPage(DMPAPER_A4)
RETURN .T.

STATIC FUNCTION SELIMPRI(OPRN)
OPRN := TPrinter():New(LOGINOM() + " Impression", .T., .T. , , .T. )
RETURN NIL

FUNCTION GETIMPRI(ADEVICES)
*----------------------------------------
LOCAl cAllEntries, cEntry, I, cName, cPrn, cPort, J

cAllEntries := STRTRAN( GetProfString( "Devices" ), Chr( 0 ), CRLF )
FOR I:= 1 TO MlCount( cAllEntries )
cName := MemoLine( cAllEntries,,I)
cEntry := GetProfString( "Devices",cName,"")
J := 2
WHILE ! EMPTY(cPort := StrToken(cEntry,J++,","))
// AADD(aDevices,TRIM(cName))
AADD(aDevices,TRIM(cName) + "," + CENTRY) // CHIDIAK
ENDDO
NEXT
RETURN aDevices

/code]
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Re: "No Default Printer" message on Windows 7 64-bit (Urgent)

Postby James Bott » Fri Apr 30, 2010 2:48 pm

Hua,

// Returns the name of the Windows default printer
function getPrinter()
return GetProfString( "windows", "device" , "" )
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: "No Default Printer" message on Windows 7 64-bit (Urgent)

Postby StefanHaupt » Fri Apr 30, 2010 4:18 pm

Hua,

hua wrote:Thanks Stefan. I can't find GetDefaultPrinter() in the source but I did find GetPrintDefault(). I assume that's the one you meant?


No, I meant GetDefaultPrinter(), it exists in xHarbour, I don´t know if it exists in harbour, too.
There are two functions I´m using, first is GetPrinters(), which returns a list of all installed printers (the printernames) and the second is GetDefaultPrinter(), which returns a String containing the name of the default printer. Both functions are not implemented in FWH, but in xHarbour ! In FWH there are similar functions with other names.

Code: Select all  Expand view
aPrinters := GetPrinters()
cDefault := GetDefaultPrinter()


hua wrote:Unfortunately, it doesn't address the logic that I want to implement. See, as a feature, in our program we allow user to select a printer and the program will later on always print to it without disturbing the setting of which printer is set to default in the control panel. This is the code that does the part of selecting and memorizing the printer name:


I have a similar function in my app, too, but I don´t use PrinterSetup(), which calls the windows printer dialog. I´m using the array returned from GetPrinters(), put it in a listbox and let the user select the printer. Later on I can print wtih PRINT oPrint ... TO <xModel>, where xModel is the selected printer. In your case xModel can be your public var zPrinter.
Maybe this is a suggestion for you.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: "No Default Printer" message on Windows 7 64-bit

Postby hua » Mon Sep 27, 2010 7:25 am

Hi all,
Thanks to all those that replied and tried to help. I've manage to get my hand on a Win7 64-bit and the problem is still there. I don't understand what's going on but so far these are my findings:

i. Previewing a report using \Samples\TestPrn2.prg and TestRtf.prg works
ii. PrinterSetup() doesn't call up the windows setup printer dialog box.
iii. The only thing not working are my modules themselves. After linking in printer.prg and inserting a code to inspect the return value of the following
Code: Select all  Expand view
elseif cModel == nil
      ::hDC  := GetPrintDefault( GetActiveWindow() )


::hDC seems to always be 0 eventhough GetActiveWindow() returns a valid handle

iv ComDlgXErr() in printer.prg always returns PDERR_NODEFAULTPRN (0x1008)

v. ::GetModel() in printer.prg returns empty spaces

In short, I'm stumped and would appreciate any other pointers. Thanks.

p.s. Would having a public variable called oWnd contribute to this? I'm just grappling in the dark here
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit

Postby hua » Mon Sep 27, 2010 8:42 am

Ok. Someone just suggest to me that it's possible that message appear because there is no printer physically attached to the workstation. I still don't think that's likely as I could preview the few programs in \Samples. I'll keep you guys posted if I come up with anything conclusive
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit

Postby gkuhnert » Mon Sep 27, 2010 10:33 am

hua wrote:Ok. Someone just suggest to me that it's possible that message appear because there is no printer physically attached to the workstation. I still don't think that's likely as I could preview the few programs in \Samples. I'll keep you guys posted if I come up with anything conclusive

Now and then I have the same problem (with Vista 64bit). It seems it only occurs if my computer is on for some time without trying to print anything. I also don't have a printer directly connected to my pc. I'll try for some days connecting an actual printer to my pc and will share my findings! However, as this problem doesn't occur on a regular basis, it will take some time ;)
Best Regards,

Gilbert Kuhnert
CTO Software GmbH
http://www.ctosoftware.de
User avatar
gkuhnert
 
Posts: 274
Joined: Fri Apr 04, 2008 1:25 pm
Location: Aachen - Germany // Kerkrade - Netherlands

Re: "No Default Printer" message on Windows 7 64-bit

Postby hua » Wed Oct 06, 2010 8:41 am

Well, I'm out of ideas. I even activate the Administrator account and run the exe just to be sure it's not due to some weird permission issue in Win7.

Now the message that I get everytime I try to print is "No printer installed". Just for the sake of seeing what's gonna happen I change the sentence to PRINTER oPrn FROM USER. When I did that Windows display the "You don't have permission to access" message. Of course \SAMPLES\testprn2.prg runs fine every time.

Antonio, any ideas? The only thing I could pinpoint for sure now is ::hDC in printer.prg is always 0
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit

Postby James Bott » Wed Oct 06, 2010 2:20 pm

Hua,

Of course \SAMPLES\testprn2.prg runs fine every time.


So if that runs fine then this should NOT give you a 0.

Code: Select all  Expand view
  PRINT oPrn NAME "Testing the printer object from FiveWin" PREVIEW
   msgInfo( oPrn:hDC )


Is that correct?

Where in PRINTER.PRG is hDC zero?

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: "No Default Printer" message on Windows 7 64-bit

Postby Randal » Wed Oct 06, 2010 3:22 pm

Hua:

I believe your application is being opened with limited permissions.

Right click on the icon and select properties. Click the Advanced button on the Shortcut tab and check the box to "Run As Administrator"

Also, click on the Compatibility tab. Check the box to "Run this program in compatibility mode for:", Win XP sp3 is fine.

After doing the above does it work?

Regards,
Randal

hua wrote:Well, I'm out of ideas. I even activate the Administrator account and run the exe just to be sure it's not due to some weird permission issue in Win7.

Now the message that I get everytime I try to print is "No printer installed". Just for the sake of seeing what's gonna happen I change the sentence to PRINTER oPrn FROM USER. When I did that Windows display the "You don't have permission to access" message. Of course \SAMPLES\testprn2.prg runs fine every time.

Antonio, any ideas? The only thing I could pinpoint for sure now is ::hDC in printer.prg is always 0
Randal
 
Posts: 260
Joined: Mon Oct 24, 2005 8:04 pm

Re: "No Default Printer" message on Windows 7 64-bit

Postby hua » Thu Oct 07, 2010 9:27 am

Hi Randal,

I think I can safely eliminate permission as the issue, (then again it actually kinda behave that way). Here's a summary of what I've done:
i. Run as administrator
ii. Linked in manifest to auto-elevate the exe's priviledge to Admin
iii. Enabled the hidden Administrator account on Win7 and use that one to login and execute my program.
iv. Turn off UAC altogether.

The programs are actually on a file server (FreeNAS) and being run from the Win7 client, so Set Compatibility can't be used as it only works with local files.

What makes me confuse and giving me a headache is FWH\Samples\testprn2.prg works perfectly even if I run it from the file server.

From searching the forum it seems I'm the only one facing this issue. Maybe I'm stuck in a twilight zone or something that's why this strange thing happens to me and only me :roll:

Hmm... I can't recall trying to run it locally. Maybe I did but then forgotten about it. I'll try that next
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1038
Joined: Fri Oct 28, 2005 2:27 am

Re: "No Default Printer" message on Windows 7 64-bit

Postby Richard Chidiak » Thu Oct 07, 2010 11:27 am

Just a shot hopefully not in the dark

I searched quite a while for a problem concerning an "ini" file placed in windows directory , problem occuring on win7 ,

I finally found that windows "virtualizes" some files created by a 32 bits app , this means you can have the same file with the same name in the windows folder twice...

This problem took me a while to find out and the solution was that i had 2 ini files having the same names... one was "virtualized" by windows. This happens when security in control panel is set to "prompt the users"

My application was using either of the 2 files without any logic, i got rid of the virtualized one and everything got back to normal.

Check if you are using an ini file ...

Maybe it can help,

Richard
http://www.cbati.com

Uestudio
Fwh 13.05 Harbour 3.2 MSVC 2013
User avatar
Richard Chidiak
 
Posts: 946
Joined: Thu Oct 06, 2005 7:05 pm
Location: France

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 19 guests