Error with PrnGetPort()
Error with PrnGetPort()
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
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
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Error with PrnGetPort()
Try this:
EMG
Code: Select all
cPort := StrToken( GetProfString( "Devices", cModel, "" ), 2, "," )
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 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.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
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.
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.
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Try
EMG
Code: Select all
PRINT oPrn
IF oPrn:hDC = 0
// Error
ENDIF
ENDPRINT
- Badara Thiam
- Posts: 160
- Joined: Tue Oct 18, 2005 10:21 am
- Location: France
- Contact:
I have found the same problem : GPF, with FW 2.5.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
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
Badara Thiam
http://www.icim.fr
http://www.icim.fr
- Badara Thiam
- Posts: 160
- Joined: Tue Oct 18, 2005 10:21 am
- Location: France
- Contact:
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)
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
http://www.icim.fr
- Badara Thiam
- Posts: 160
- Joined: Tue Oct 18, 2005 10:21 am
- Location: France
- Contact:
Go to Fivewin for Clipper forum, there is news printing functions.
or click here :
http://fivetechsoft.com/forums/viewtopic.php?t=3143
Regards,
or click here :
http://fivetechsoft.com/forums/viewtopic.php?t=3143
Regards,
Badara Thiam
http://www.icim.fr
http://www.icim.fr