Odd behavior with printing on Windows with x-platform app

With help from this community, I finished my first real app in Xojo:

It lets a warehouse staffer simply type in the SKU of a returned item and print out a CODE-39 barcode to a desktop Dymo label printer, without needing to go into our ERP system.

Label printing is a pain, so the app lets an IT staffer go into Page Setup, set the right paper/label size, orientation, etc. and it saves the settings to a file. So after initial setup by IT, the end user always has the label settings correct. When they print a label, it comes out great… on the Mac where I developed this.

I cross-compiled for Windows, where I need to deploy. The first/worst problem is that when the user clicks the Print button, instead of the Windows OS Print window coming up, this window appears:

It keeps saying Connecting but nothing ever happens. Once you click the Cancel button, it goes away and you see the Windows OS Print window, and you can then print.

What do you think could be triggering this window? It doesn’t appear in any other native Windows apps, so I would think it has to do with my code for printing, which is this:

// print the label
Var g As Graphics
Var pageSetup As PrinterSetup
pageSetup = New PrinterSetup
pageSetup.Settings = App.s
g = pageSetup.ShowPrinterDialog
If g <> Nil Then
  g.FontName = "IDAutomationHC39M Free Version"
  g.FontSize = 12
  // Print bar code label
  g.DrawText(TextArea_BarCode.text,15,50)
end if

Does that also happen on another machine?
Since no one seems to have reported this already, I’d suspect some software installed on this specific computer is the culprit.

No. I have a very clean Windows 11 PC on the desk, and also set up a brand new Windows 11 VM in Parallels on my Mac and they both have the same behavior. I uninstalled Dymo’s software thinking maybe that was the culprit but had the same odd behavior.

My next step may be to install the IDE on Windows, see what happens when I run locally from there. That will certainly help identify if the problem had something to do with the compilation.

Are you by any chance trying to use a printer setup string from one OS in another one? If yes, let me inform you that you can’t. And more, it must be set and reused only in the machine it was previously setup. You should not even try to use a setup from one machine into another one with the same OS (due to possible different drivers, printer names, configs, etc).

Is there a way to validate a page setup string?

I’m not aware of any.

I researched the Mac’s Cocoa API for printing. There’s probably a path to trial-run a print setting string to see if it is valid. There’s no explicit function and it may just have too much built-in error recovery to act as a validation method.

For the curious and sufficiently motivated, the NSPrintInfo object stores the print configuration of various Cocoa objects (windows, documents, etc), which is represented as key-value pairs in a mutable dictionary. This dictionary can then be rendered as a plist. Presumably, one could take a putative page setup plist and throw it into that dictionary and see what happens.

Xojo config “string” is a Xojo only thing combining internal needs of Xojo including a binary part at the end. And it looks very different depending on the OS.

OK, so now at least I know… “it’s not me!” :slight_smile:

On a clean Windows 11 PC, with Dymo label software drivers installed, I installed the Xojo IDE latest build and opened the example project, “Mailing Labels” in the Printing section.

When I click “Print Labels” it also opens the window I first included in the original question (and pasted below again). I hit Cancel in that window and then it reveals the Windows Print dialog box. I select Landscape there, hit Print, and the label prints perfectly.

How to make this Window above NOT appear when printing? THAT is the question.

Is the label printer connected USB or Network?
Maybe choose custom install for the printer and deselect the connection tools you don’t need to see if that is causing the connection window opening.

I run the Xojo project on Win 10/11 and works so has to be something in the Dymo software install/configuration

It’s very simple. Save the PrinterSetup string, which is binary and will be unique to this machine, then restore it later. You only need to display the setup dialogs once, but you must display them once.

I thought the OP had already followed the advice from Rick, or I was hoping so :grin:

Obviously not. I don’t see where the disconnect is.

Me either
Have to wait for OP to reply or we are just spinning our wheels

This is the code I use in my page setup routine. I set it once the first time the app runs on a computer. It saves settings to file, so end user doesn’t have to do this every time they launch the app.

Var pageSetup As PrinterSetup
pageSetup = New PrinterSetup
If pageSetup.ShowPageSetupDialog Then
  App.s = pageSetup.Settings
End If

// save printer settings to file

Var f As FolderItem
Var bs As BinaryStream

// get a folderitem
f = New FolderItem("Whole File", FolderItem.PathModes.Native)

// create a binary file with the type of text (defined in the file types dialog)
bs = BinaryStream.Create(f, True)

// check to see if it was created
If bs <> Nil Then
  //write the contents of the editField
  bs.Write(App.s.ConvertEncoding(Encodings.UTF8))
  
  // close the binaryStream
  bs.Close
End If

What is your code to read it back?

I really appreciate all of the help and insight!

When the app opens/loads:

Var f As FolderItem
Var bs As BinaryStream

// get a folderitem
f = New FolderItem("Whole File", FolderItem.PathModes.Native)

// make sure it exists before we try to read it
If f.Exists Then
  
  // open the folderitem as a binary file without write privelages
  //     To open with write priviledges, use true instead of false
  bs = BinaryStream.Open(f, False)
  
  // make sure we have a binary stream to read from
  If bs <> Nil Then
    
    // read the whole binaryStream
    App.s = bs.Read(bs.Length, Encodings.UTF8)
    
    // close the binaryStream
    bs.Close
  End If
End If

I’m lost then. Does that not work?

On a Mac, the app works perfectly.
On Windows, where I really need to deploy it, that odd “Connecting to printer” window comes up and once I hit cancel, you get the print dialog box and it works reasonably well (minor layout formatting issues to resolve). That’s the whole issue. Going to see if it’s printer-specific from the Dymo printer next…

I don’t think the print settings should be used with an encoding on Windows (it’s binary data, while on Mac, it’s “text” data).
Have you tried removing the “Encodings.UTF8” optional parameter when reading the data back?