Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printernames longer than 32 Chars are exported wrong #313

Closed
Tanarri opened this issue Mar 30, 2022 · 4 comments
Closed

Printernames longer than 32 Chars are exported wrong #313

Tanarri opened this issue Mar 30, 2022 · 4 comments
Assignees
Labels

Comments

@Tanarri
Copy link
Contributor

Tanarri commented Mar 30, 2022

Hi,

in my System I have installed a printer, which is shared from a windowsserver 2016. The printername in my windows 10 is "Godex_VersandB_gross" on "W2K16SERVER"
grafik

On exporting a report of my access 2013 project the printername exported as "\\W2K16SERVER\Godex_VersandB_gro192.168.0.236" in the .json

Full JSON

{
  "Info": {
    "Class": "clsDbReport",
    "Description": "rpt_etikett_neutral_100x150 Print Settings"
  },
  "Items": {
    "Device": {
      "DriverName": "winspool",
      "DeviceName": "\\\\W2K16SERVER\\Godex_VersandB_gro192.168.0.236",
      "Port": "192.168.0.236",
      "Default": false
    },
    "Printer": {
      "Orientation": "Landscape",
      "PaperSize": 259
    },
    "Margins": {
      "LeftMargin": 0.0396,
      "TopMargin": 0.1667,
      "RightMargin": 0.0396,
      "BotMargin": 0.1667,
      "DataOnly": false,
      "Width": 5.8271,
      "Height": 3.5521,
      "DefaultSize": true,
      "Columns": 1,
      "ColumnSpacing": 0,
      "RowSpacing": 0,
      "ItemLayout": "Horizontal Columns",
      "FastPrint": 1,
      "Datasheet": 0
    }
  }
}

The Printername is truncated after 32 Bytes because the structure "clsDevMode,tDevMode" has only place for 32 Bytes.

Private Type tDevMode
    strDeviceName(1 To 32) As Byte
    intSpecVersion As Integer
    intDriverVersion As Integer
    intSize As Integer

The limit of 31 Characters (plus terminating NULL) is a problem accoring to:
https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/14703-printer-names-longer-than-31-characters

To get a list with the complete printernames here is a example:
https://forum.powerbasic.com/forum/user-to-user-discussions/source-code/25008-demo-initialize-printdlg-for-named-printer?t=24359

But: How to do the match beetween the trucated printername and the complete printername?
Any suggestions?

PS: The "Build from source" of the project with the truncated incorrect printername could not be done without user interaction. Access is asking for the correct printer, because "\\W2K16SERVER\Godex_VersandB_gro192.168.0.236" isn't found on my system.

Greetings
Tanarri

@joyfullservice
Copy link
Owner

Thanks for reporting this! I did some testing with a very long printer name, and I think I found the problem. The great news is that it looks like it is very easy to resolve. 😄 For some reason I was truncating the device name in the DevNames structure to 32 characters...

image

This should not be needed because we are not dealing with a 32 character fixed length field like we have on the DevMode structure. Instead, we are using null terminators and offsets to return the printer name, driver, and port from a combined string buffer of 255 characters in length.

image

This should support any reasonable sized printer name well beyond the 32 character DevMode limit. After removing the truncation, I was able to successfully build my test database with no errors. After building, the report is using the long printer name specified in the source file.

image

I will make this change shortly on the master and dev branches...

@joyfullservice joyfullservice self-assigned this Mar 30, 2022
@joyfullservice
Copy link
Owner

Just to clarify this a little further, we are dealing with two different WinAPI structures in clsDevMode. The DevMode structure handles most of the printer settings, but truncates the printer name to 32 characters. The DevNames structure does not suffer from the 32 character limit, and includes the entire printer device name. The export process reads the printer name from the non-truncated DevNames data, and that is what is written to the printer settings json file.

The reason we were seeing a problem on build is that I was (inadvertently) truncating the printer name when loading it back into the DevNames structure. This in turn is loaded into the report export file just before it is imported into the database. Since the name was partially missing, it could not automatically map to the desired printer when the report was opened. Since the printer name was broken, this would then affect subsequent exports.

joyfullservice added a commit that referenced this issue Mar 30, 2022
The printer name was unnecessarily truncated to 32 characters when loading to the DevNames structure. This was causing problems when building from source when a specified printer name was longer than 32 characters in length. Fixes #313
@joyfullservice
Copy link
Owner

@Tanarri - You can either hot-fix your version, or build the master branch from source. Let me know if this resolves the problem with your project. (Note that you will need to fix the printer name in the report, save it, then export source to ensure that the printer settings .json file has the full printer name before building from source.)

@Tanarri
Copy link
Contributor Author

Tanarri commented Mar 31, 2022

@joyfullservice
I have build the master branch and the problem is resolved
Thanks for your fast help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants