我有一个 Winforms 应用程序,它生成自己的 PrintDocument 对象进行打印。经过我自己的测试,它在 XP 和 Windows 7 中运行良好,但一位用户在 Vista 中选择带有打开文档的打印命令时出现以下异常:
************** Exception Text **************
System.ArgumentException: Handle 0 is not valid.
at System.Drawing.Printing.PrinterSettings.SetHdevmode(IntPtr hdevmode)
at System.Windows.Forms.PrintDialog.UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, Int16 copies, Int32 flags, PrinterSettings settings, PageSettings pageSettings)
at System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, WndProc hookProcPtr, PRINTDLG data)
at System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at Deck_Studio.DSMain.PrintDeck(Object sender, EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItem.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Command.DispatchID(Int32 id)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
我很难弄清楚这个错误的性质以及复制它的任何潜在方式。可执行文件上的清单处于“受限”权限模式,甚至让用户以管理员身份运行应用程序也会产生错误。