WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.


Printer Controller

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

pSetDefPrt Problem Notifying Other Applications on XP


I am having a problem on Windows Xp trying to set the default printer using the function pSetDefPrt. When I open Excel version 2000, and go to the File Print dilaog it complains about an invalid printer specified.

I modified my code to manually broadcast to OS regarding change in printer to assist in resolving issues with apps that do not seem to pick up the print change correctly. It sends broadcast two different ways.

; Required parameters for printer broadcast string 
PrinterBroadcastString=strcat(Printer_Share, "," , PRT_PORT, "," , sp_unc) ; Set the default Windows printer 

;  device="HP DeskJet 500,HPDSKJET,LPT1:" 
DllCall( DaDll, long:"SendMessageA", long:-1, long:DMC, long:0, lpstr:"%printerbroadcaststring%") 

;; this is the WM_WININICHANGE part 

DllCall( DaDll, long:"SendMessageA", long:-1, long:WININICHG, long:0, lpstr:"%printerbroadcaststring%") 
Any Ideas how we can resolve this issue?


Note: in version 39003 of the printer extender the pSetDefPrt function changed how it processed on Windows 2000 and XP. It should better handle notifying other applications that the default printer has been changed.

For older versions, you could use this code which specifically calls the SetDefaultPrinter API, if you are running on NT, 2000,and XP. Otherwise is calls pSetDefPrt.


printers = pGetPrtList(0)

printer =AskItemList("Choose Default Printer", printers, @tab, @sorted, @single)

if WinVersion(1)==5 ;2000/XP

      ;BOOL SetDefaultPrinter(

      ;  LPCTSTR pszPrinter  // default printer name



      ret = DllCall( DaDll, long:"SetDefaultPrinterA", lpstr:printer) 

      if ret==0

            Message("Error: Unable to set default printer",DllLastError())



else ;95/98/ME

      ret = pSetDefPrt(printer)

      if !=1

            Message("Error: Unable to set default printer",pGetErrorCode())




Article ID:   W15856
File Created: 2017:07:28:13:58:38
Last Updated: 2004:03:30:15:41:11