外部异常C0000006 [英] External exception C0000006

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

问题描述

我在Delphi中写了一些程序,当我从一个磁盘上运行它时。在某些时候,我需要在应用程序运行时拔下钥匙上的磁盘。如果我在一台计算机上这样做,至少有一千克的ram,一切都没问题。当我在512MB的机器上这样做时,我得到一个外部异常C0000006。如果我没有错,这是因为操作系统正在尝试读取下一行代码,但找不到它的资源(意思就是应用程序没有加载到ram),这是荒谬的,因为它是一个500kb的应用程序。



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



哦,我的Delphi应用程序是Windows XP下的控制台应用程序。 $ b

解决方案

您需要做的是告诉Windows将整个程序加载到内存中,而不是允许它在需要时要求加载页面。我已经成功地完成了运行CD的应用程序。我现在没有我的代码,但我记得我发现了如何在源代码中为这个梦幻般的开源安装程序Inno Setup提供了一些提示。



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



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

  {$ SetPEFlags IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP} 

这告诉Windows可执行文件将从可移动介质中使用,因此将可执行文件加载到内存(或交换文件)中。那么你不需要担心首先将文件复制到机器等等。



对于Delphi< 2006年,您可以下载强制要执行的页面的路径。有一个如何在C ++中执行的示例这里(除非你找到一种修改链接时间后PE标题的方法,这看起来很复杂)



N @


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).

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

解决方案

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.

Edit: 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}

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.

For Delphi < 2006, 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天全站免登陆