Page 1 of 1
Error with PrnGetPort()
Posted: Wed May 24, 2006 6:04 pm
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
Re: Error with PrnGetPort()
Posted: Wed May 24, 2006 7:49 pm
by Enrico Maria Giordano
Try this:
Code: Select all
cPort := StrToken( GetProfString( "Devices", cModel, "" ), 2, "," )
EMG
Posted: Wed May 24, 2006 8:23 pm
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
Posted: Wed May 24, 2006 9:00 pm
by Enrico Maria Giordano
Windows NT/2000/XP automatically redirect it to the registry. Try to believe.
EMG
Posted: Wed May 24, 2006 9:47 pm
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.
Posted: Thu May 25, 2006 6:53 am
by Enrico Maria Giordano
Try
Code: Select all
PRINT oPrn
IF oPrn:hDC = 0
// Error
ENDIF
ENDPRINT
EMG
Posted: Thu May 25, 2006 9:35 pm
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.
******************
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
Posted: Fri May 26, 2006 1:22 am
by ralph
thanks to all, I will try your suggestions.
Ralph
Posted: Mon May 29, 2006 10:29 pm
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)
Posted: Tue May 30, 2006 7:56 am
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,