Odd behavior with printing on Windows with x-platform app

I’ve never seen a “Connecting to printer” window. Maybe there’s an issue with printer driver. I also agree with Arnaud to drop the encodings.

I tried dropping the encoding and got a printing error, so added it back.

I tried removing the printer and printing to a standard HP printer and still that window pop up when I go to print. Still trying to work the problem… thanks for all the tips, ideas, etc.

Here’s an old old project that may give you some ideas. Or validate that you’re doing it right and there’s some kind of bug somewhere.

https://www.dropbox.com/scl/fi/610kh4eals58wzioo0xtk/twoprinters.xojo_binary_project?rlkey=xm0ob6mm2gb6tmoioxx6wmv15&st=tsjrxelh&dl=0

Thanks Tim. Looking forward to digging into this today!

This goes for save too: you do not specifically tell a target folder where Xojo will save / read the printer setup.
You haave to create a folder to the location where you will save / read the data, using SpecialFolder.ApplicationData, then save and read from that folder.

Tim, I ran your application and have the same issue with that intermediate printer connect window popping up.

I tried switching to an office HP laserjet to see if it was anything specific to the dymo label printer but same issue.

I have this problem on two computers and the one commonality between them is that they run the latest release of Windows 11. I wonder if this is Windows 11 specific maybe?

And @Emile_Schwarz I was wondering where the file gets saved for my prefs. I will look up the folder creation per your advice and see if that changes anything, but the app does successfully save prefs in some unknown default location.

[quote=“Scott Kahn, post:27, topic:81756, username:Scott_Kahn”]
but the app does successfully save prefs in some unknown default location.[/quote]

And from where does it read it ? The Read rights may not be set…

I modified a bit your code and here you are:

Var pageSetup As PrinterSetup
Var mySettings As String

pageSetup = New PrinterSetup
If pageSetup.ShowPageSetupDialog Then
  mySettings = pageSetup.Settings
End If

// save printer settings to file

Var Settings_FI As FolderItem
Var f As FolderItem
Var bs As BinaryStream

// get a folderitem
'f = New FolderItem("Whole File", FolderItem.PathModes.Native)
Settings_FI = SpecialFolder.ApplicationData
If Settings_FI = Nil Then MessageBox "Nil"
Settings_FI = Settings_FI.Child("Dymo_SetUp")
Settings_FI.CreateFolder

f = Settings_FI.Child("Settings.bin")
// 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(mySettings)
  
  // close the binaryStream
  bs.Close
End If

I changed App.s to a local variable.

Other change is to save the settings where it is due.

For readings, you just do the same, but read (no create folder).

Reading the settings from the file:

Var pageSetup As PrinterSetup
Var mySettings As String

// Get printer settings to file

Var Settings_FI As FolderItem
Var f As FolderItem
Var bs As BinaryStream

// get a folderitem
Settings_FI = SpecialFolder.ApplicationData.Child("Dymo_SetUp")
If Settings_FI = Nil Then MessageBox "Nil"

f = Settings_FI.Child("Settings.bin")
// create a binary file with the type of text (defined in the file types dialog)
bs = BinaryStream.Open(f, False)

// check to see if it was created
If bs <> Nil Then
  //write the contents of the editField
  mySettings = bs.Read(f.Length)
  
  // close the binaryStream
  bs.Close
  
  // Store the settings for current use:
  pageSetup = New PrinterSetup
  pageSetup.Settings = mySettings
End If

Works here, but I do not have a Windows machine, so…

the line:

Settings_FI.CreateFolder

breaks when I select Page Setup… haven’t tried the code on a Mac. Just working in the Windows IDE at the moment.

Write permissions probably.

OS believe they own the computer and we have to ask it permission to do whatever we want to do.

Place before the folder creation:

Settings_FI.Launch

and run: a folder will be opened and you then can check its permissions and eventually change them.

You do not disclose what Windows flavor it is, nor if it is running in plane mode or with full (cloud, OneDrive , etc.) “features”.

I just checked your way to save the settings:
f = New FolderItem("Whole File", FolderItem.PathModes.Native)

The file is saved in the project folder. For the moment, I suggest to use that (for write, then read), until you know how to save to a proper place on the Windows machine. This will allows you to fine tune your printing code.

Unless you use a full path or SpecialFolder, the file will be created next to the executable. In debug (Run) mode, the executable is created in a subfolder that is deleted when you stop debugging, which also deletes the settings file. Upon your next debug run, it will not find the settings and go through the setup process again.

@Tim_Hare Ha. This explains a lot! Thank you. :slight_smile:

@Emile_Schwarz Forgot to let you know, this is Windows 11 Professional. One PC is joined to a Windows AD. Other machine is virtual – my Mac with Parallels running a clean install of Windows 11 Pro and just a local admin account. Both behave exactly the same way.

I have also confirmed that the printer settings are being successfully saved and read from at start. Thank you @Tim_Hare for pointint out the run time vs. compile issue… Yes, when I compile the build, the settings file stays and is read from, but in run-time, it gets erased.