Reputation: 1355
I have a MFC application that I want to distribute via USB flash drives. One of the the requirement for the application is that when a user unplugs the USB flash, the MFC app should exit itself.
I added code to detect USB flash removal and exit the app when that occurs. The app exits itself fine most of the time when USB flash is unplugged. But sometimes (50%), I would get a "AppName.exe has stopped working." error message in Windows 7. When running under the debugger, I get more details and it's a "First-chance exception: 0xC0000006: In page error." error.
After some googling, that error seems to be caused by the fact that the underlying media is removed and the memory manager is unable to read from the media (USB flash in this case). Reference 1: In page error 0xc0000006 Reference 2: http://blogs.msdn.com/b/oldnewthing/archive/2008/12/04/9172708.aspx
This MFC app is a small single executable file program. My question is if there's a way to force Windows OS to load an entire .exe file into memory before executing it. My thinking is that if I can get Windows to load the entire program into memory before executing, then the memory manager wouldn't need to access the disk when USB flash is removed and the unwanted error message problem might just go away.
Thanks for you help!
Upvotes: 3
Views: 975
Reputation: 941635
Link the program with the /SWAPRUN option. Also available as an EditBin.exe option to do it later.
Upvotes: 8