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.

TechHome

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


Question:

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 

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

;; this is the WM_WININICHANGE part 

WININICHG=26 
DaDll=Strcat(DirWindows(1),"USER32.DLL") 
DllCall( DaDll, long:"SendMessageA", long:-1, long:WININICHG, long:0, lpstr:"%printerbroadcaststring%") 
Any Ideas how we can resolve this issue?

Answer:

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.

AddExtender("WWPRT34i.DLL")

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

      ;);

      DaDll=Strcat(DirWindows(1),"winspool.drv") 

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

      if ret==0

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

            exit

      endif

else ;95/98/ME

      ret = pSetDefPrt(printer)

      if !=1

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

            exit

      endif

endif

Article ID:   W15856
File Created: 2004:03:30:15:41:12
Last Updated: 2004:03:30:15:41:12