我在打印的时候,在页面设置对话框中重新选择打印机后进行打印,却报出一个异常“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”然后我进行跟踪发现异常出现在这句代码“paper.Attach(pageSetupDialog.PrinterSettings.GetHdevmode(pageSetupDialog.PageSettings).ToInt32(), pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32());”paper是 IPaper paper; paper = new PaperClass();这么创建的,是ESRI.ArcGis.Output.IPaper接口的对象;
下面这一段应该是它的具体的异常信息:
" 在 System.Drawing.Printing.PrinterSettings.SetHdevnames(IntPtr hdevnames)\r\n 在 System.Windows.Forms.PrintDialog.UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, Int16 copies, Int32 flags, PrinterSettings settings, PageSettings pageSettings)\r\n 在 System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, WndProc hookProcPtr, PRINTDLG data)\r\n 在 System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)\r\n 在 System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)\r\n 在 System.Windows.Forms.CommonDialog.ShowDialog()\r\n 在 PGIS.FormPrintSet.Print() 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Form\\FormPrintSet.cs:行号 447\r\n 在 PGIS.FormPrintSet.btnPrint_Click(Object sender, EventArgs e) 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Form\\FormPrintSet.cs:行号 438\r\n 在 System.Windows.Forms.Control.OnClick(EventArgs e)\r\n 在 System.Windows.Forms.Button.OnClick(EventArgs e)\r\n 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r\n 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n 在 System.Windows.Forms.Control.WndProc(Message& m)\r\n 在 System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n 在 System.Windows.Forms.Button.WndProc(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)\r\n 在 System.Windows.Forms.Form.ShowDialog()\r\n 在 PGIS.FormBaseMap.actnPrint_Execute(Object sender, EventArgs e) 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Form\\FormBaseMap.cs:行号 177\r\n 在 Crad.Windows.Forms.Actions.Action.OnExecute(EventArgs e)\r\n 在 Crad.Windows.Forms.Actions.Action.DoExecute()\r\n 在 Crad.Windows.Forms.Actions.Action.handleClick(Object sender, EventArgs e)\r\n 在 Crad.Windows.Forms.Actions.Action.target_Click(Object sender, EventArgs e)\r\n 在 System.EventHandler.Invoke(Object sender, EventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)\r\n 在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)\r\n 在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)\r\n 在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)\r\n 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n 在 System.Windows.Forms.Control.WndProc(Message& m)\r\n 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n 在 System.Windows.Forms.ToolStrip.WndProc(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Application.Run(Form mainForm)\r\n 在 PGIS.Program.Main() 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Program.cs:行号 34\r\n 在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n 在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n 在 System.Threading.ThreadHelper.ThreadStart()"高手帮忙看看 谢谢
下面这一段应该是它的具体的异常信息:
" 在 System.Drawing.Printing.PrinterSettings.SetHdevnames(IntPtr hdevnames)\r\n 在 System.Windows.Forms.PrintDialog.UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, Int16 copies, Int32 flags, PrinterSettings settings, PageSettings pageSettings)\r\n 在 System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, WndProc hookProcPtr, PRINTDLG data)\r\n 在 System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)\r\n 在 System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)\r\n 在 System.Windows.Forms.CommonDialog.ShowDialog()\r\n 在 PGIS.FormPrintSet.Print() 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Form\\FormPrintSet.cs:行号 447\r\n 在 PGIS.FormPrintSet.btnPrint_Click(Object sender, EventArgs e) 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Form\\FormPrintSet.cs:行号 438\r\n 在 System.Windows.Forms.Control.OnClick(EventArgs e)\r\n 在 System.Windows.Forms.Button.OnClick(EventArgs e)\r\n 在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)\r\n 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n 在 System.Windows.Forms.Control.WndProc(Message& m)\r\n 在 System.Windows.Forms.ButtonBase.WndProc(Message& m)\r\n 在 System.Windows.Forms.Button.WndProc(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Form.ShowDialog(IWin32Window owner)\r\n 在 System.Windows.Forms.Form.ShowDialog()\r\n 在 PGIS.FormBaseMap.actnPrint_Execute(Object sender, EventArgs e) 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Form\\FormBaseMap.cs:行号 177\r\n 在 Crad.Windows.Forms.Actions.Action.OnExecute(EventArgs e)\r\n 在 Crad.Windows.Forms.Actions.Action.DoExecute()\r\n 在 Crad.Windows.Forms.Actions.Action.handleClick(Object sender, EventArgs e)\r\n 在 Crad.Windows.Forms.Actions.Action.target_Click(Object sender, EventArgs e)\r\n 在 System.EventHandler.Invoke(Object sender, EventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)\r\n 在 System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)\r\n 在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)\r\n 在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)\r\n 在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)\r\n 在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)\r\n 在 System.Windows.Forms.Control.WndProc(Message& m)\r\n 在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)\r\n 在 System.Windows.Forms.ToolStrip.WndProc(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)\r\n 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)\r\n 在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)\r\n 在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)\r\n 在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)\r\n 在 System.Windows.Forms.Application.Run(Form mainForm)\r\n 在 PGIS.Program.Main() 位置 F:\\软件\\陈敏个人\\PGIS\\PGIS\\Program.cs:行号 34\r\n 在 System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)\r\n 在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n 在 System.Threading.ThreadHelper.ThreadStart()"高手帮忙看看 谢谢
好像是这个参数错了pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32(),
这个比较难搞 你从头到尾检查一下 有时候报错的地方不一定是出错的地方
这个比较难搞 你从头到尾检查一下 有时候报错的地方不一定是出错的地方
好像是这个参数错了pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32(),不知道怎么改啊