I know there are API functions wich I can use
(GetDefaultprinter(),Setdefaultprinter(),Enumprinters()):
What I did:
I declared the global external function :
FUNCTION boolean GetDefaultPrinter( REF string szPrinter, REF ulong
dwBuffer ) LIBRARY "kernel32.dll"
My code:
string s_printer
ulong buffer
buffer = 260
s_printer = Space( buffer )
IF GetDefaultPrinter( s_printer, buffer ) THEN
MessageBox( "Default Printer", s_printer )
END IF
Problem : I always get the error : "Error calling external function
GetDefaultPrinter..." for the line where it's called.
Maybe the library "kernel32.dll" isn't right, because I have founded in the
MSDN library that you have to use the library "Winspool.lib". But
powerbuilder can not open this library when I declare that library in the
global external function.
Another problem : this function doesn't support Windows 95/98.
Any ideas, to help me get and set the default printer and get a
printerlist?(on windows 95/98/2000/NT)
Thank you,
Sandra
The issue is that PB uses the default printer if you never change the
printer selection with PrinterSetup. After this routine has been called, PB
maintains the printer to use internally. This is so that your application
can print to a printer without changing the printer for all other
applications that run on the system. Very important, especially now that
Windows is starting to be used in "multi-user" environments such as Terminal
Server and user expectations increase to more than one application active at
a time.
If your printing is from datawindow sources, then there are numerous cheap
and functional utilities that can be used to control printer selection and
printer options. If your printing is from PB Script, then you are basically
in the mode of calling PrinterSetup and then PrinterOpen. The common issue
is the "Cancel" button on the PrinterSetup function dialog does not give any
indication back to the application, so users must be trained to use the
"Cancel button to cancel printer selection not the following print
operation".
I suspect that PB8 will offer additional enhancements in this area.
"Sandra Lambrechts" <sandra_l...@servico.be> wrote in message
news:7PMU8bG...@forums.sybase.com...
STEP 1 - Check if printer driver 'X' is installed:
string ls_key, ls_subkeylist[], ls_driver_name
int li_items, li_index, li_rtn
environment lenv
boolean lb_found
lb_found = FALSE
ls_driver_name = 'X' (Note: You will have to replace this line with
specific registry printer description)
ls_driver_ini = 'Printer X,XDRIVER,LPT1:' (Note: you will have to
replace this line with specific printer ini setting - go to control panel
and manually set specific printer as default, then, open c:\Windows\win.ini
file for value where line is device=...)
// get a list of installed printer drivers
li_rtn =
RegistryKeys("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Pri
nters", ls_subkeylist)
IF li_rtn <> -1 THEN
// go through all printer drivers until driver 'X' found or end of list
is reached
li_items = UPPERBOUND(ls_subkeylist)
FOR li_index = 1 TO li_items
IF ls_subkeylist[li_index] = ls_driver_name THEN
lb_found = TRUE
EXIT
END IF
NEXT
END IF
// if the 'X' driver is found return true
IF lb_found THEN
RETURN TRUE
END IF
STEP 2 - Change default driver:
// get default printer
RegistryGet("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Prin
ters", "Default", RegString!, ls_currentprinter)
// if default printer is not the 'X' printer
IF ls_currentprinter <> ls_driver_name THEN
// set 'X' printer as default
SetProfileString("WIN.INI", "windows", "device", ls_driver_ini)
END IF
STEP 3 - Perform print
STEP 4 - Reset default printer if you had to change it
Stephan Donati
Fortisoft Corporation
"Sandra Lambrechts" <sandra_l...@servico.be> wrote in message
news:7PMU8bG...@forums.sybase.com...