外部异常 C0000006 [英] External exception C0000006

查看:65
本文介绍了外部异常 C0000006的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Delphi 中编写了一些程序,当我从磁盘上运行它时.在某些时候,我需要在应用程序运行时拔下钥匙上的磁盘.如果我在至少有 1gb 内存的计算机上执行此操作,则一切正常.当我在一台 512mb 的机器上执行此操作时,我收到一个外部异常 C0000006.如果我没记错的话,这是因为操作系统试图读取下一行代码,但找不到它的资源(意思是,应用程序没有加载到内存中),这是荒谬的,因为它是一个 500kb 的应用程序.

I've wrote some program in Delphi and when I am running it from a disk on key. At some point I'm required to unplug the disk on key while the application is running. If I do this on a computer with at least 1gb of ram everything is okay. When I do this on a machine with 512mb I get an external exception C0000006. If I'm not mistaken, this is because the OS is trying to read the next line of code but cannot find the resource for it (meaning, the application wasn't loaded to the ram) which is absurd because it's a 500kb application.

我该如何解决这个问题?或者至少以更优雅的方式处理这个异常?(因为它是外部异常,所以我无法捕获它).

How can I solve this? or at least handle this exception in a more elegant way? (Since I can't catch it since it's an external exception).

哦,我的 Delphi 应用程序是 windows xp 下的控制台应用程序.

Oh, and my Delphi application is a console application under windows xp.

推荐答案

您需要做的是告诉 Windows 将整个程序加载到内存中,而不是让它在需要时要求加载页面.对于从 CD 运行的应用程序,我已经成功地做到了这一点.我现在没有代码,但我记得我在出色的开源安装程序 Inno Setup 的源代码中找到了有关如何执行此操作的提示.

What you need to do is tell windows to load your whole program into memory, rather than allowing it to demand load pages when it needs to. I have done this successfully for applications running off a CD. I don't have the code with me right now, but I recall that I found hints on how to do it in source for the fantastic open source install program Inno Setup.

实际上,经过一些研究,您可以使用 Delphi 编译器指令告诉 Windows 加载完整的可执行文件.如果您有 Delphi > 2006,这将起作用.这将导致您永远不会收到外部异常.

Actually, after doing a little research, you can use a Delphi compiler directive to tell windows to load the full executable. This works if you have Delphi > 2006. This will have the effect that you will never get the external exception.

将此行放在您的应用程序项目文件中:

Put this line in your applications project file:

{$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP}

这告诉 windows 可执行文件将从可移动媒体使用,因此将可执行文件加载到内存(或交换文件)中.然后你就不用担心先把文件复制到机器上之类的了.

This tells windows that the executable is going to be used from removable media, so load the the executable into memory (or the swap file). Then you don't need to worry about things like copying the file to the machine first, etc.

编辑 2:我目前可以访问 Delphi 7,正如其他人所指出的,我可以使用以下代码确认这也适用于 Delphi 7(可能还有 Delphi 6):>

Edit 2: I currently have access to Delphi 7 and I can confirm, as noted by others, that this also works with Delphi 7 (and likely Delphi 6) with the following code:

const
  IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP = $0400;

{$SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP}

对于德尔福 <6、可以走下强制执行分页的路径,C++中有一个例子这里(除非你找到链接时间后修改PE头标志的方法,看起来很复杂)

For Delphi < 6, you can go down the path of forcing the executable to be paged in. There is an example of how to do it in C++ here (unless you find a way to modify the PE header flags after link time, which looks to be complicated)

N@

这篇关于外部异常 C0000006的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆