I don't know why I get no printer selected when call PrintSetup(). Let me give you the scenario where it fails when I don't see any printer highlighted in PrintSetup().
We have system configuration maintenance program where we set the printer by the PSR file (Each PSR file belongs to some process like part_invoice.psr file will belong to part sales order, workshop_invoice.psr for workshop invoice etc.
For few programs, we set the printer as default printer i.e <default> or <windefault>
For few programs we set the printer as <Selectable> means it will open printer select dialog box when give print command.
We store these configuration setting into config table.
Our programs have facility to print and archive the document (We have check box for those options). For archive, we have Amyuni PDF driver which print/save as file into PDF. Here are the steps we follow during Print and Archive.
String lb_printdlg = TRUE // Always display print dialog
1 Look into Configuration table and look what is the printer option
2 If <Selectable> Then
Set Dw_Obj.Modify("Datawindow.Printer=''");
lb_printdlg = TRUE //Open dialog box.
ElseIf <default> Then
lb_printdlg = FALSE //Don't open dialog box.
Else
Call Windows Printer from Registry based on OS Type
Case Windows
RegistryGet('HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers', 'default', ls_winprinter)
Case WindowsNT
RegistryGet('HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows', 'Device', ls_winprinter)
Call ls_currentPrinter = PrintGetPrinter()
If ls_currentPrinter <> ls_winprinter //Windowsdefault printer is not same as PrintGetPrinter()
Dw_Obj.Object.DataWindow.Printer=''
PrintSetPrinter(ls_WinPrinter) //Set Windows Default Printer as printer.....
lb_printdlg = FALSE//Don't Open dialog box.
3. Dw_Obj.Print(True, lb_printdlg ) //lb_printdlg will determine whether to open the dialogbox or not.
4. PrintSetPrinter(ls_currentprinter) //Restore the printer changed in <WinDefault> condition...
For Archive
ls_printer = PrintGetPrinter() //Store current printer
PrintSetPrinter("Amyuni Printer")
Dw_Obj.saveAs(); // Overwrite SaveAs() and call Amyuni API.
PrintSetPrinter(ls_printer) //Restore printer...... Here we have issue as ls_printer is coming as blank when we don't see any printer highlighted in PrintSetup() dialog box.
Kindly advice.
Just to let you know our company is moving dedicated physical servers to AWS cloud server (VM machine) and installing the application over cloud but in this process also nothing is changing except the machine (Physical to cloud).