C++访问冲突崩溃

发布于 2024-12-28 17:54:37 字数 380 浏览 1 评论 0原文

当我尝试访问此特定指针时,应用程序崩溃并显示 c0000005 访问冲突错误。

如何捕获此错误并防止其关闭进程,就像在 C# 中使用 try&catch 块一样。 或者在使用该内存区域之前如何检查该区域的访问是否被拒绝?

示例:

MyClass** a = (MyClass**)(0x12345678);
a[0]->b = 1;

我正在访问指针表并设置类成员之一的值。 这确实有效,但问题是“0x12345678”并不总是在该区域加载类。该地址有一个值,但它没有指向正确的内存区域,也没有保存值 0。

请记住,这是一个加载到应用程序中的 DLL,我不再拥有该应用程序的源代码。 所以我尝试动态设置应用程序的设置。

When I attempt to access this specific pointer, the application crashes and shows a c0000005 access violation error.

How can I catch this error and keep it from closing the process as I would in C# with a try&catch block.
Or how could I check if the access is denied to that area of memory before I use it?

Example:

MyClass** a = (MyClass**)(0x12345678);
a[0]->b = 1;

I am accessing a table of pointers and setting the value of one of the members of the class.
This does work, but the issue is that "0x12345678" doesn't always have the classes loaded in that area. The address has a value, but it doesn't point to the correct area of memory and it doesn't hold the value 0.

Keep in mind, this is a DLL that is loaded into a application that I no longer have the source for.
So I'm trying to set the settings of the application dynamically.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下雨或天晴 2025-01-04 17:54:37

您可以使用结构化异常处理 来捕获此类错误。特别是,过滤 EXCEPTION_ACCESS_VIOLATION

只要确保您知道吞下异常时在做什么:如果您的垃圾地址指向防护页面,您可能会看到描述的行为 此处

You can use Structured Exception Handling to trap these sorts of errors. In particular, filter for EXCEPTION_ACCESS_VIOLATION.

Just make sure you know what you're doing when you swallow the exception: if your garbage address points to a guard page, you might see the behaviour described here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文