且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

外部异常C0000006

更新时间:2022-10-14 22:47:49

您需要做的是告诉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@