Please do not reply to this email- if you want to comment on the bug, go to the URL shown below and enter your comments there.
Changed by [EMAIL PROTECTED] http://bugzilla.ximian.com/show_bug.cgi?id=80519 --- shadow/80519 2007-01-14 12:15:12.000000000 -0500 +++ shadow/80519.tmp.21067 2007-01-14 12:15:12.000000000 -0500 @@ -0,0 +1,88 @@ +Bug#: 80519 +Product: Mono: Class Libraries +Version: 1.2 +OS: GNU/Linux [Other] +OS Details: +Status: NEW +Resolution: +Severity: +Priority: Normal +Component: Sys.Drawing. +AssignedTo: [EMAIL PROTECTED] +ReportedBy: [EMAIL PROTECTED] +QAContact: [EMAIL PROTECTED] +TargetMilestone: --- +URL: +Cc: +Summary: System.Drawing.Printing doesn't find the default printer. + +1) PreviewPrintController throws exception because it doesn't have valid +PrinterSettings associated with the PrintDocument +2) PrintDocument has some PrinterSetttings but they are not valid because +the PrinterName is empty +3) PrinterName is empty because SysPrn.Service.DefaultPrinter is empty. +4) Since System.Drawing.Printing.PrinterSettings.InstalledPrinters (witch +gets it from SysPrn.Service.InstalledPrinters) returns my printer name +this means that SysPrn.Service has "cups_installed" set to true +5) This leads me to the conclusion that "IntPtr cupsGetDefault ();" from +"libcups" returns empty string + +Based on the information here: + +http://www.cups.org/documentation.php/api-cups.html#cupsGetDefault2 + +It says "Applications should use the cupsGetDests() and cupsGetDest() +functions to get the user-defined default printer, as this function does +not support the lpoptions-defined default printer." + +I made a test on my machine (Ubuntu 6.06) and found a solution that works +on my machine. I used some code from mono as a code base and this piece of +code finds my default printer. + + private void button2_Click (object sender, EventArgs e) + { + int printerCount; + IntPtr savedDests = IntPtr.Zero; + IntPtr dests; + CUPS_DESTS dest = new CUPS_DESTS (); + int destStructSize = Marshal.SizeOf (typeof (CUPS_DESTS)); + string defPrinter = string.Empty; + + //if (cups_installed == false) + // return col; + + printerCount = cupsGetDests (ref savedDests); + + dests = savedDests; + for (int i = 0; i < printerCount; i++) { + dest = (CUPS_DESTS) Marshal.PtrToStructure (dests, typeof +(CUPS_DESTS)); + + if (dest.is_default != 0) { + defPrinter = Marshal.PtrToStringAnsi (dest.name); + } + // Free allocated unmanaged memory + Marshal.FreeHGlobal (dest.name); + Marshal.FreeHGlobal (dest.instance); + Marshal.FreeHGlobal (dest.options); + dests = new IntPtr (dests.ToInt64 () + destStructSize); + } + // Free allocated unmanaged memory + Marshal.FreeHGlobal (savedDests); + + textBox1.Text = defPrinter; + } + + [DllImport ("libcups", CharSet = CharSet.Ansi)] + static extern int cupsGetDests (ref IntPtr dests); + + public struct CUPS_DESTS + { + public IntPtr name; + public IntPtr instance; + public int is_default; + public int num_options; + public IntPtr options; + } + +I hope this should be enough to fix the problem. _______________________________________________ mono-bugs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-bugs
