0

By writing a portable WIn32 app I want to make sure that all the proper settings are done.

I googled for it and found the compiler IMAGE_FILE_NET_RUN_FROM_SWAP switch.

I tried to include it in my dpr file just like this:

{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP} // THIS ONE!
{$R *.dres}
{$R *.res}

Anyway Delphi XE7 says

[dcc32 Error] Project1.dpr(330): E2003 Undeclared identifier: 'IMAGE_FILE_NET_RUN_FROM_SWAP'

Anyway by reading Embarcaero wiki it seems the name is fine.

Any suggestion?

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • Do you understand what the error message states? It's very clear to me. I suspect that your eyes have glazed over and you've just assumed that you won't be able to understand it. I strongly recommend learning to read error messages carefully. – David Heffernan Oct 09 '15 at 06:57
  • yes undeclared identifier means i must tell where to look for this identiier and it is in WInapi.windows... By the way @DavidHeffernan could you please tell me which are the pitfalls of using such a compiler switch if any? – UnDiUdin Oct 09 '15 at 07:21
  • 1
    http://stackoverflow.com/questions/6953739/are-there-risks-associated-with-image-file-removable-run-from-swap-or-image-file – David Heffernan Oct 09 '15 at 07:25
  • Thanks, I swear i googled but i wasn't lucky to find that. Thanks! – UnDiUdin Oct 09 '15 at 07:43
  • 1
    Second hit on Google for me!! – David Heffernan Oct 09 '15 at 07:47
  • @DavidHeffernan i noticed those compiler directive make the starting time of the exe much slower (exe is 90MB, so run from LAN it takes more time). It would be nice to pass a command line parameter to the exe (like `Project1.exe -SafeLanMode:Y` ) to set the directive optionally. Is it possible to set a compiler directive "after compilation"? Or any trick to do this? – UnDiUdin Oct 13 '15 at 09:19
  • 1
    That's the price you pay. What you are controlling is a flag that changes the behaviour of the loader. All that happens far below command line arguments. They are only processed once the executable is running. Obviously it is loaded before it runs. If you want quick startup, don't force it to run from swap. What you really want to do is to put the executable on a local drive, and not a network drive. – David Heffernan Oct 13 '15 at 09:31
  • @DavidHeffernan thanks, the price to pay is very high, i started this invstigation because a customer had an exception on a specific machine when running the exe from LAN. Since customres want fast applicatiions, adding forcefully a 5 seconds delay sounds stupid. One option could be to build 2 exes, but this is not a good choice in my context. So I think now i master the issue but the solution is not ok, likely formatting the machine will solve the issue (issue is on a win 8.1 machine, and on many other win 8.1 machines the issue is not there) – UnDiUdin Oct 13 '15 at 09:41
  • It won't be an issue with the machine on which the executable runs. It will be an issue with the network there. Put the executable on the local drive, and the job is done. – David Heffernan Oct 13 '15 at 09:45

1 Answers1

4

Just include Winapi.Windows in your uses clause (this is where IMAGE_FILE_NET_RUN_FROM_SWAP is declared):

uses
  Winapi.Windows, ...

{$R *.dres}
{$R *.res}
{$SetPEFlags IMAGE_FILE_NET_RUN_FROM_SWAP}
Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128