- Aug 9, 2022
- 21
- 2
- 3
- Customer Identifier
- E114627
Creating a printer object with the following code
returns a printer object for the system's default printer. Normally, this is the default printer configured in the system settings. When connecting to a machine via RDP, however, clients can optionally redirect the default printer to the one configured for the client machine. In this case, applications running within the RDP session are expected to print to the redirected printer instead.
However, on certain operating systems (Windows Server 2016/Windows 10 and newer) the redirected printer is not reported correctly to the Xbase++ runtime. This causes the default printer configured for the RDP server to be used instead. This issue is described in the following PDR: http://www.alaska-software.com/scri...KAGE=PUBLICDTS&WAA_FORM=DISPLAYPDR&PDRID=7101.
As a work-around, a Win32 API function can be used for determining the name of the (possibly redirected) default printer, which is outlined in the following code:
The above function with the work-around can be used for creating a printer object as follows:
Xbase++:
oPrinter := XbpPrinter():new():create()
returns a printer object for the system's default printer. Normally, this is the default printer configured in the system settings. When connecting to a machine via RDP, however, clients can optionally redirect the default printer to the one configured for the client machine. In this case, applications running within the RDP session are expected to print to the redirected printer instead.
However, on certain operating systems (Windows Server 2016/Windows 10 and newer) the redirected printer is not reported correctly to the Xbase++ runtime. This causes the default printer configured for the RDP server to be used instead. This issue is described in the following PDR: http://www.alaska-software.com/scri...KAGE=PUBLICDTS&WAA_FORM=DISPLAYPDR&PDRID=7101.
As a work-around, a Win32 API function can be used for determining the name of the (possibly redirected) default printer, which is outlined in the following code:
Xbase++:
#include "dll.ch"
#include "set.ch"
#include "collat.ch"
EXTERN BOOL Win32GetDefaultPrinter( @pszBuffer AS STRING, @pcchBuffer AS UINTEGER ) IN winspool.drv NAME GetDefaultPrinter
FUNCTION GetDefaultPrinterName()
LOCAL cName := Space( 255 )
IF Win32GetDefaultPrinter(@cName, 255)
cName := RTrim( cName )
IF Set(_SET_CHARSET) == CHARSET_OEM
cName := ConvToOemCp( cName )
ENDIF
RETURN cName
ENDIF
RETURN ""
The above function with the work-around can be used for creating a printer object as follows:
Xbase++:
oPrinter := XbpPrinter():new():create( GetDefaultPrinterName() )
Last edited by a moderator: