Error with PrnGetPort()

Post Reply
User avatar
ralph
Posts: 63
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Error with PrnGetPort()

Post by ralph »

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: 63
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Post by ralph »

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
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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

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

Post by ralph »

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
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Post by Badara Thiam »

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
ralph
Posts: 63
Joined: Fri Nov 18, 2005 11:15 pm
Location: Lima - PERU

Post by ralph »

thanks to all, I will try your suggestions.

Ralph
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Post by Badara Thiam »

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
Contact:

Post by Badara Thiam »

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
Post Reply