Monday, August 03, 2009
Apply Application Manifest at Compile Time with Projecthook
Some Time Ago...
I wrote a blog entry,
PE Files, UAC, Reg-Free COM, and Other Crazy Stuff - Part 2
, that detailed how to view and edit the application manifest that is inserted into VFP compiled modules. I also took some time to explain why someone would want to do such a thing. The top two reasons most VFP developers want to do this is to elevate permissions under Window's
User Account Control
(UAC) and to provide for
. I guess you may also find the need to edit or add strings to the PE file's String Table resource (minority of VFP developers) which is provided for as well.
While the code and concepts detailed in that previous blog entry were advanced and pretty decent (if i do say so myself), it suffered from a couple of bugs and most VFP developers probably found it more than a little difficult to implement "out-of-the-box" for their projects that needed elevated UAC permissions or Reg-Free COM. I attempt to make things slightly more straight-forward and bug-free in this blog entry.
Enter the ProjectHook Class
There's plenty of good information on the
ProjectHook class online
and in the VFP 9.0 SP2 help file (get the latest and greatest help file
out on VFPX
), so I won't go into a great amount of detail here. I simply wanted an easy way to apply a new manifest to a VFP executable after I had built a project. The ProjectHook class provides a
event where I can get the fullpath of the EXE being built and an
event which allows me to perform operations immediately after the EXE is built. So, this class provided exactly what i needed and made applying a modified manifest a breeze.
How to Use ProjectHookEx.vcx
In order to use the projecthookex.vcx (download provided at the bottom of this blog entry), you simply need to unzip and copy it somewhere and then open up one of your projects and go into the Project Information dialog (accessible either by right-clicking the project or under the Project system menu... look for Project Info) and set the Project Class property as shown in the following screen shot...
...then simply click OK, exit your project and reopen your project. The projecthook isn't instantiated until you reopen the project for the first time after setting the Project Class property.
The default settings for the hookex class are set so that the default VFP 9.0 SP2 manifest, which has its
set to asInvoker, is changed to requireAdministrator. Take a look inside hookex's AfterBuild event for the code that accomplishes this (short and sweet). You'll see a couple commented out lines of code in the AfterBuild event that show how to accomplish Reg-Free COM and String Table resource edits as well. In any event, once the Project Class is set for your project hookex will be instantiated and ready to go any time you open and build your project. When the manifest is applied it will be echoed to the screen so you can see it and ensure that it has been applied (you can turn this off by changing the moduleresourceeditor class's
property if you so desire).
External Manifests Anyone?
For those of you that prefer to use an external manifest for your executables, you can do so by setting the moduleresourceeditor class's externalmanifest property. The cool thing about this is that the myproj.exe.manifest file is created in the same directory as your executable and the executable's internal manifest is removed to prevent it from interfering with your external manifest. Then you can edit the external manifest using favorite XML editor or even notepad. This was one of the enhancements I added to this that is not in the code that I posted in the original blog entry regarding PE Assembly/Application Manifests.
There are plenty of improvements and enhancements (automatically searching project for all COM components and automatically adding them to the manifest for instance) that could be made to this class and I hope that my readers will make suggestions and even try their hand at coding a few. There are lots of
good uses for VFP's ProjectHook
class. I'd love to hear from you and what you feel needs to be done to improve this ProjectHook class. But, I'm cool if you just want to read this, download the class library and use it. Until next time... VFP Rocks!
Download the Latest Version of the ProjectHookEx Class Library
(12 KB approx.)
Monday, August 03, 2009 12:50:30 PM (GMT Daylight Time, UTC+01:00)
Tuesday, August 04, 2009 10:52:03 AM (GMT Daylight Time, UTC+01:00)
once again great content.
We are using a very similar selfbuild ProjectHookClass for this purpose. In addition i take additional textstrings to add to the versioninfo so that i can add e.g. "beta" to the cFileVersion String in the resources... or change the make-version which is always "0" in VFP, so my exe can show up as "126.96.36.19911 Beta" on the version-page of Windows. Currently i am using the Resourcehacker (cmdline) to add/change the versionresource because there is no way to change it with VFP. Perhaps with your knowledge of the PE / resource structs you'll find a way to do this without using Resourcehacker ;-)
On another issue i would like to ask if you are still working on the vfpconnection.fll? There is an issue with real large downloads when using httpget(). The preset timeout triggers even when the download is still in progress. ...and there is no way to change SetResponseTimeout() during Progress() because the connection is already active. I could of course start with generous 5min-Timeout, but i don't think that would be very nice especially if the server stopped responding right after a few seconds...
If you have currently no time for this, we would be glad to have a look into the C-code for the FLL if you are willing to share that.
In any way... you could reach me on ms [a t] datensysteme.de
All comments require the approval of the site owner before being displayed.
(will show your
Comment (Some html is allowed:
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, sup, u
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
© Copyright 2014 Craig Boyd
| Page rendered at Sunday, November 23, 2014 12:36:44 AM (GMT Standard Time, UTC+00:00)
On this page....
Blog Posts by Month/Year
SPS Blog Home
Visit SweetPotato Software
Contact Craig Boyd
Lisa Slater Nicholls