我在打印的时候,在页面设置对话框中重新选择打印机后进行打印,却报出一个异常“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”然后我进行跟踪发现异常出现在这句代码“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()"高手帮忙看看 谢谢

解决方案 »

  1.   

    打印地图的,是GIS出图时打印。很郁闷啊,我现在发现,我使用别人共享出来的打印机作为默认打印机,完全没问题。当我换成自己机上的虚拟的microsoft Office Document Image Writer 时,在执行打印就会出错,并且整个程序强制退出,谢谢。
      

  2.   

    我现在将别人的一个共享的打印机设为默认的打印机,然后在页面设置的时候我换成虚拟的打印机然后打印或打印预览的时候就出现了上面的错误,就是这句paper.Attach(pageSetupDialog.PrinterSettings.GetHdevmode(pageSetupDialog.PageSettings).ToInt32(), pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32());”
    好像是这个参数错了pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32(),
      

  3.   

    个人认为.net自带的打印控件是不会出错的,能不能是你要打印的文件的dll出错呢 比方说你打印的是word或者excel的com 组件报的错误呢
    这个比较难搞 你从头到尾检查一下 有时候报错的地方不一定是出错的地方
      

  4.   

    个人认为.net自带的打印控件是不会出错的,能不能是你要打印的文件的dll出错呢 比方说你打印的是word或者excel的com 组件报的错误呢
    这个比较难搞 你从头到尾检查一下 有时候报错的地方不一定是出错的地方
      

  5.   

    试试,paper.Attach(pageSetupDialog.PrinterSettings.GetHdevmode(pageSetupDialog.PageSettings).ToInt32(), pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32());” 
    好像是这个参数错了pageSetupDialog.PrinterSettings.GetHdevnames().ToInt32(),不知道怎么改啊  
      

  6.   

    你是采用arcgis组件里的打印2D地图模块的借口把
      

  7.   

    我可以给你说一下关于虚拟打印机adobe的一款,  其实要把图像流化,这里只说GIS地图输出虚拟打印机这个过程,就是地图控件将空间数据加载进来后,将这些数据组织成一个Image对象,Image对象可以IO.stream流,虚拟打印机就有这样的接口接这个流
      

  8.   

    GIS2D的地图输出,如果是实打印机可以(GIS组件肯定可以把image的图像按照扫描线,一条条输入到物理打印机里),而虚拟打印机不行,一般在做这个开发时,要两套组件一起调用(一套是GIS组件,一套是虚拟打印机组件),也就是说把image数据输入到虚拟打印机这个借口需要自己动手写一下,指望打印对话框窗体,来完成数据匹配打印到虚拟打印机好像不行。Arcgis是否在Ipage借口里提供了这种用打印对话框窗体来切换各种虚拟打印机方式我不清楚(arcgis本身自己提供了可以预览地图的功能模块,至于能不能直接接到MS的虚拟打印机我就不清楚了),但是SuperMap的不行,需要像我上面说的那样,两套组件一起调用来完成。祝楼主可以成功啊