询问者
C# + Win7(Win2008)openFileDialog对话框的“尝试读取或写入受保护的内存”错误

问题
-
C#的Winform程序,内有一个很简单的openFileDialog1.ShowDialog() == DialogResult.OK语句,发布后在XP、2003环境下使用都正常,但是在Win7(64位)、Win2008下反复执行第三次就会报“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。”错误。会是什么原因造成的?
开发是使用VS2008+.Net2.0。
下面是报错信息:
************** 异常文本 **************
System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
在 System.Windows.Forms.FileDialogNative.IFileDialog.Unadvise(UInt32 dwCookie)
在 System.Windows.Forms.FileDialog.RunDialogVista(IntPtr hWndOwner)
在 System.Windows.Forms.FileDialog.RunDialog(IntPtr hWndOwner)
在 System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
在 System.Windows.Forms.CommonDialog.ShowDialog()
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)- 已编辑 cpcZane 2011年1月10日 5:34
全部回复
-
我是用clickonce发布的,客户端不支持这种运行方式吧?
dear
这是UAC造成的权限问题,你的代码若要存取被Windows保护的位置(从VISTA以上就有这些保护),必须要做一些设定。
[C#在Windows7下的UAC控制]
http://hi.baidu.com/meback/blog/item/5c1d92580d267ad59c8204ea.html
客户端也可以按右键以系统管理员身份执行,WINNT架构的系统都有
秘訣無它,唯勤而已 http://www.dotblogs.com.tw/yc421206/- 已编辑 Leo Liu - MSFTModerator 2011年1月10日 5:37 Enabled the link.
-
Hi cpc Zane,
欢迎来到MSDN论坛。
请试试将您的程序编译成64位,
或者检查程序是否占用了些本地资源导致调用函数版本不对,或者位数不对。
Sincerely,
Leo Liu
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
-
Hi cpcZane,
请尝试将这行代码注释掉Application.EnableVisualStyles();
禁用系统或控件的视觉样式来尝试一下。
并请尝试在Vista或XP的兼容模式下面允许看看。
Sincerely,
Leo Liu
Leo Liu [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.