Error with PrnGetPort()

Error with PrnGetPort()

Postby ralph » Wed May 24, 2006 6:04 pm

I use this function in my program (FWH 2.7 + xHb 09950)

cPort := PrnGetPort()

but when the printer is off or there is no printer installed i got an Harbour exception error and the aplication is closed. Does any one has solved this problem ?

Ralph
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Re: Error with PrnGetPort()

Postby Enrico Maria Giordano » Wed May 24, 2006 7:49 pm

Try this:

Code: Select all  Expand view
cPort   := StrToken( GetProfString( "Devices", cModel, "" ), 2, "," )


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby ralph » Wed May 24, 2006 8:23 pm

there is no such "Devices" in my win.ini.

I use windows 2000 profesional.

I wonder if there is a way to know if there is a printer installed, or the printer status. All the functions PrnGetname(), PrnGetport(), etc. fails if the printer is unavailable.

Ralph
Last edited by ralph on Wed May 24, 2006 9:06 pm, edited 1 time in total.
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Postby Enrico Maria Giordano » Wed May 24, 2006 9:00 pm

Windows NT/2000/XP automatically redirect it to the registry. Try to believe. :-)

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby ralph » Wed May 24, 2006 9:47 pm

thank's Enrico for your sugestion. But my problem persist, as in your code you need to know the printer name.

I would like to send a message to the user like "There is no printer installed or printer is not available"

But i can't use PrnGetName(), as in xHb (not in Clipper) the aplication crashes if the printer is unavailable.
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Postby Enrico Maria Giordano » Thu May 25, 2006 6:53 am

Try

Code: Select all  Expand view
PRINT oPrn
    IF oPrn:hDC = 0
        // Error
    ENDIF
ENDPRINT


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Postby Badara Thiam » Thu May 25, 2006 9:35 pm

ralph wrote:there is no such "Devices" in my win.ini.

I use windows 2000 profesional.

I wonder if there is a way to know if there is a printer installed, or the printer status. All the functions PrnGetname(), PrnGetport(), etc. fails if the printer is unavailable.

Ralph


I have found the same problem : GPF, with FW 2.5.

So, i have rewritted these functions : PrnGetName() and PrnGetPort().
This work ok under 98 and XP. Tell me if you have a problem please.
8)

******************
FUNCTION WinDefPrn()
******************
* To replace PrnGetName(), failed function of Fivewin 2.5
* Return the name of the default Windows printer
* by take it directly in the Windows registry

* Pour remplacer la fonction défaillante PrnGetName() de Fivewin 2.5
* Retourne le nom de l'imprimante par défaut
* en le prenant directement dans le registre Windows

LOCAL cDefPrn := ""
LOCAL oReg := TReg32():New(HKEY_CURRENT_CONFIG, "System\CurrentControlSet\Control\Print\Printers")
IF oReg:nError = 0
cDefPrn := oReg:Get("Default", "")
ENDIF
oReg:Close()
oReg := NIL
RETURN cDefPrn
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
 
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France

Postby ralph » Fri May 26, 2006 1:22 am

thanks to all, I will try your suggestions.

Ralph
User avatar
ralph
 
Posts: 79
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Postby Badara Thiam » Mon May 29, 2006 10:29 pm

Hello my friends,

All is right ??
ok...

Can you also test this, please ?

This function return an array containing
the list of all of the printers the user can use...

Regards,

******************
FUNCTION WINGETPRN()
******************
* Recherche les imprimantes installées sous windows
* dans le registre de Windows (remplace le WIN.INI
* qui est obsolète sous Windows 2000 et suivants)
* Auteur Badara Thiam

LOCAL TIMP := {}
LOCAL nHandle
LOCAL cValue
LOCAL n1
LOCAL n2
LOCAL nok
LOCAL nLen
LOCAL cSubkeys
LOCAL aHKey := HKEY_LOCAL_MACHINE

cSubKeys := "System\CurrentControlSet\Control\Print\Printers"

IF RegOpenKey( aHKey, cSubKeys, @nHandle ) == 0
n1 := 0
DO WHILE .T.
cValue := ""
n2 := RegEnumKey( nHandle, n1, @cvalue )
IF n2 = 0
IF ASCAN(TIMP, STRTRAN(cValue, "," , "\")) = 0
AADD(TIMP, STRTRAN(cValue, "," , "\"))
ENDIF
ELSE
EXIT
ENDIF
n1 ++
ENDDO
RegCloseKey( nHandle )
ENDIF
RETURN ACLONE(TIMP)
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
 
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France

Postby Badara Thiam » Tue May 30, 2006 7:56 am

Go to Fivewin for Clipper forum, there is news printing functions.

or click here :

http://fivetechsoft.com/forums/viewtopic.php?t=3143

Regards,
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
 
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France


Return to FiveWin for Harbour/xHarbour

Who is online

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