编组访问冲突
正确的函数声明是:
[DllImport("user32.dll")]
static extern int SetScrollInfo (IntPtr hwnd, int n, ref SCROLLINFO lpcScrollInfo, bool b);
我这样声明它:
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
static extern int SetScrollInfo (IntPtr hwnd, int n, SCROLLINFO lpcScrollInfo, bool b);
这可能是访问冲突异常的原因吗?
这是我得到的异常:
UI 线程中发生未处理的异常 System.AccessViolationException:尝试读取或写入受保护 记忆。这通常表明其他内存已损坏。
在 System.Drawing.SafeNativeMethods.PrintDlg(PRINTDLGX86 lppd) 处 System.Drawing.Printing.PrinterSettings.GetDefaultPrinterName() 位于 System.Drawing.Printing.PrinterSettings.get_PrinterNameInternal()
在 System.Drawing.Printing.PrinterSettings.get_PrinterName()
The correct function declaration is:
[DllImport("user32.dll")]
static extern int SetScrollInfo (IntPtr hwnd, int n, ref SCROLLINFO lpcScrollInfo, bool b);
I declared it like:
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
static extern int SetScrollInfo (IntPtr hwnd, int n, SCROLLINFO lpcScrollInfo, bool b);
Can this be the reason for the access violation exception?
This is the exception I get:
Unhandled exception occured in UI thread
System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
at System.Drawing.SafeNativeMethods.PrintDlg(PRINTDLGX86 lppd) at
System.Drawing.Printing.PrinterSettings.GetDefaultPrinterName() at
System.Drawing.Printing.PrinterSettings.get_PrinterNameInternal()
at System.Drawing.Printing.PrinterSettings.get_PrinterName()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有发布 SCROLLINFO 结构定义。在您发布的代码中,我看到 bool 参数类型不正确:将其定义为 int。 Win32 BOOL是32位值,它与.NET中的int匹配。
发布完整代码:PInvoke 定义并调用 SetScrollInfo 以获取更多信息。
You didn't post the SCROLLINFO structure definition. In the code you posted, I see that bool parameter type is incorrect: define it as int. Win32 BOOL is 32-bits value, it matches int in .NET.
Post full code: PInvoke definitions and call to SetScrollInfo to get more information.
结构声明:
调用:
SCROLLINFO 滚动信息1 = 新的 SCROLLINFO();
SetScrollInfo(new HandleRef(this, Handle), 0,scrollinfo1, true);
structure declaration:
invocation:
SCROLLINFO scrollinfo1 = new SCROLLINFO();
SetScrollInfo(new HandleRef(this, Handle), 0, scrollinfo1, true);