.manifest support in dzPrepBuild

It has taken a while but I have eventually arrived in the “modern” Windows world. After many years of sticking with Windows XP (and Linux) I have updated two computers to Windows 8 (both 64 bit) and another two to Windows 7 (64 bit and 32 bit).

In doing so I have been made aware of some annoyances of Windows >= Vista, one of them being the virtual store. This is a convenience feature Microsoft added to Vista and later Windows versions to allow users to continue using old programs without escalating their security issues. This feature virtualizes write access to directories in the file system and branches of the registry that are read only on properly configured systems (like “c:\windows”, “c:\program files\…” or  HKey_LOCAL_MACHINE).

While Microsoft’s intention was good and normal users won’t have a problem with it, for a software developer this feature is rather inconvenient because it prevents him from realizing if his programs do something undesired. Rather than failing and in Delphi’s case raising an exception, these actions succeed and the programmer won’t notice. Even worse, he will not find the files or registry entries his programs were supposed to make in the place he expects them and possibly waste hours in trying to find out what’s wrong.

The idea was that newer software disables this feature with a .manifest resource. Unfortunately this will only work if the programmer updates his development tools to create these files and bind the resources to the program. Delphi 2007 did not know about .manifest resources so it needs some help. There are already many sites with information about this topic so I won’t repeat them. Suffice to say, that a .manifest resource is a special kind of resource that is added to an executable from a text file in xml format.

That format requires version information and also some descriptions, which are already part of an executable’s version resource so I added support for it to dzPrepBuild. As always, that program “eats its own dog food” (uses itself for building), so you can have a look at the source code on how it is done:

  • add {$ *_manifest.res} to the .dpr file, like the ($ *_version.res} and {$ *_icon.res} entries that were already in place.
  • add a pre-build event to the project which calls the prebuild.cmd file in buildtools if it isn’t already there
  • copy the template.manifest.in file from buildtools\templates to your source directory and rename it to <yourprogram>.manifest.in
  •  modify it to suit your needs
  • The pre-build event will, in addition to creating a *_version.rc file and compiling it, also create a *.manifest file from the contents of the *.manifest.in file + the version information, create a *_manifest.rc file and compile it. This compiled file will then be added by the Delphi compiler to the executable.

Voila: Your program has a valid .manifest resource and Windows will automatically disable virtual store for it. Now you can start finding all the bugs you never noticed. 😉

Since this is a tool created by one Delphi developer for other Delphi developers and you will probably want to have a look at how it is done anyway, I have not created a release. Just point your favourite svn client to http://svn.code.sf.net/p/dzprepbuild/code/trunk/ and make sure you also include the externals. The project requires Delphi XE2 to compile but it should be easy to revert back to Delphi 2007 if you desire so.