PrintJob.PrinterName only returns first character in PrintJob_Added event

May 5, 2009 at 10:15 AM


I wanted to upgrade the PrinterQueueWatch component from
version to version but have noticed
that the PrintJobEventArgs.PrintJob doesn't report the correct
UserName, PrinterName, DocumentName, etc., that is, it will
only return the first character of the string and cuts off
the rest.

For example if I want to monitor the printer: "TestPrinter"
the e.PrintJob.PrinterName returns only "T" (the first character)
in the printJob_Added(object obj, PrintJobEventArgs e) event.

The same code works well with the previous version.

Can you reproduce this behaviour?
And what is the latest stable version for production?

Thank you!

Best regards,

May 5, 2009 at 10:46 PM
Yup - the switch to unicode API calls basically broke it :-(
I'm still working out what to do to fix it - all assistance gratefully received - but if you take the 2.06.x code and turn the API declaratiuons back to ANSI it works...

2.0.4.x is your best bet for a production app. for now.
May 13, 2009 at 10:30 AM

Hi again,

first of all thank you for your answer.

Finally I had the time to debug the code and I have seen the
cause of the problem occurs in the PrinterNotifyInfo constructor.

'\\ this will only return the first letter
.InitPrinterName = item.ToString

'\\ this will only return the first letter too
.InitPrinterName = Marshal.PtrToStringAnsi(itemdata.pBuff)

'\\ working: this will return the correct name
.InitPrinterName = Marshal.PtrToStringUni(itemdata.pBuff)

But I haven't tested yet if this modification is save and recommended.

Best regards,

PS: Is the pJThis.InitPrinterName even neccessary because the
PrinterName property already contains the correct name before
the switch statement?


May 13, 2009 at 9:46 PM

Looks good so far!  Thanks