If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[VB6] XP/Vista/Win7+ Manifest Creator

This project has a slight twist. See post #28 below for yet another easy option of inserting manifests into a resource file. And at this thread, Karim Wafi offers this code as a VB IDE add-in option, but as of this latest update, his project hasn't been updated to reflect latest changes herein.

We know manifest files allow our forms to display with window themes. And we know there are 2 ways to make that happen.
1) Including an external manifest file with our application
2) Inserting that manifest file into a resource of our application

But for option #2 above, it does not use rc.exe, no batch files, and is a bit customizable. And this is the best part.... This can be done before your exe is compiled so that the manifest is compiled with your exe. You don't have to go back later to insert the manifest using rc.exe & other techniques. How easy is that? And it can be undone too!Edited: Note, either manifest technique can cause crashes when compiled exe closes & it contained VB usercontrols. To rememdy this problem, the Sub Main created by the Manifest Creator now contains a LoadLibrary/FreeLibrary call. See the Change History below for a link that has information pertaining to this problem.

Some quick notes.
:: Not fully tested yet in all scenarios. Not tested on Win7. Could use some feedback from those of you with access to that system.
-- Update: MrSmith, post #11 below, mentioned it worked with Win7
:: The attached project will create a manifest file and create a res file if needed. It can also overwrite an existing manifest file and insert into an existing res file. It can also delete embedded manifests from any VB resource file.
:: See post #2 below for step-by-step procedure for embedding manifest files

FAQ: "So, I want my app to be themed and don't want to include external manifest file(s) and I don't use a resource file. Does that mean I have to create a resource file just to embed the manifest file into my compiled application?"
Answer: YESFAQ: "I copied sub main to the clipboard and pasted it into a module. I also changed my project to start with Sub Main vs. my main form. When I run the project, my main form does not show, the project simply starts & closes. Why?"
Answer: You forgot to show your main form before exiting Sub Main.FAQ: "How do you get VB6 IDE to run using themed controls?
Answer: Use a manifest file. See post #54 on page 2 for details

You can see the differences below between unthemed controls & vista/xp themes

P.S. Remember that including theme capability requires you to initialize the common controls before your app starts. This means adding a Sub Main to your project and having the project start with Sub Main. If you don't do this, your compiled app will not load & run if it contains a manifest file or embedded manifest.

You may ask why you would want to include a manifest for common controls (i.e., buttons, textboxes, MS common controls, etc). The answer is simply appearance. For operating systems that use themes, your compiled application will look like 98% of the other apps the user is used to. It won't appear out of place or "old". There are known incompatibilities between VB and themes. Don't use frames. Within your project, common controls v5 works with themes where common controls v6 don't. Using VB's Graphical Style property on command buttons, option buttons, checkboxes prevent theming for those specific controls. Some other "bugs" may crop up. But these are just a minor annoyance vs. a major inconvenience, in my opinion.

Themes are applied to compiled applications ONLY. However, you can get a WYSIWYG version of it in IDE by having the IDE run themed. See post #54, page 2, for more information on theming the IDE

Preface: If you update a resource file that is being referenced in an open VB project, the changes made may not be visible when you open the resource file via VB's Resource Editor. In that case, simply remove the resource file from the project and re-add it back to the project, or close & re-open your project. The changes will be seen. Not recommended to write to a resource file that you have modified with VB's Resource Editor and have not yet saved the changes; unexpected results may occur.

If you do not already have an embedded manifest within your project's resource file
1. Open the Manifest Creator
2. Create a resource file and add it to your project if no resource file exists yetIf you do not want controls themed, and only want one of the other manifest portions, skip steps 3 & 4 below
3. Create a module in your project, if needed
4. Click on the button "Sub Main To Clipboard"
-- Paste text to your module.
-- Ensure pasted API/Structure declarations are moved near top of the module.
-- Add any additional ICC constants to the .lngICC = line of code. See comments in that code.
-- In the Sub Main procedure, just prior to "FreeLibrary" call, add line of code to show your main form
-- Add any other custom start-up code needed
-- Save changes
5. In bottom combobox, select "Create from VB File" and select your project's .vbp file. Press "Go"
6. Adjust any settings/values in the Manifest Creator. If you want controls themed, ensure option to include Common Controls is checked.
7. In bottom combobox, select "Write Manifest", press "Go"
8. Select "Resource Files" in browse window's bottom combobox. Locate your project's .res file and click "Save"

How to start your project with Sub Main? This must be done if you chose to include common controls in your embedded manifest
a. You should have already completed steps 1-4 above.
b. Open your project's Properties window. IDE menu: Project | [project name] Properties
c. In the General tab, select "Sub Main" from the Startup Object combobox
d. Close the properties window and save changes.

If you already have a manifest embedded in your project's resource file and you want to change it
1. Open the Manifest Creator
2. Start with Step #5 above
The old manifest will be replaced with the new manifest. Note that if you chose to include the Common Controls in the manifest, you must start your app with Sub Main, initializing common controls. See Steps 3 & 4 in previous paragraph.

If you want to delete the embedded manifest from your project's resource file
1. Open the Manifest Creator
2. In bottom combobox, select "Delete Manifest", press "Go"
3. Select "Resource Files" in browse window's bottom combobox. Locate your project's .res file and click "Open"
You may or may not want to remove the Sub Main from your project, if it exists.

Re: [VB6] XP/Vista Manifest Creator

Originally Posted by Cunae

Hi, great project - maybe you should add which Components/References must be selected for the project to compile without errors?
/Cunae

Not sure I understand the suggestion. The checklist I posted in #2 above, if followed, does ensure compilation without errors. Because you have the option of including a Vista security and/or controls manifest, the options are fairly simple:
1. Vista manifest, no special handling needed
2. Controls manifest, include Sub Main with the code provided via the "Sub Main To Clipboard" button, and set your startup object to Sub Main.

If you are asking which references you should be adding to your project (i.e., ADO, Scripting, etc)? Not applicable to this project. VB does that for you anyway by popping up a window saying you are missing a reference.

Re: [VB6] XP/Vista Manifest Creator

Ok, my intention was just to inform you my experience after I unzipped your Vista Manifest Creator project and then compiled it, compilation failed because of missing references/components ("Unzip the project and compile it, then run it.."). I did find out to select the necessary component and compile ok because as you say VB helps you by popping up a window, so I am happy and satisfied with your solution. I am seeing forward too to others testing it with Windows 7

Re: [VB6] XP/Vista Manifest Creator

Thanx. I'll have to look at the project again; maybe I left in some reference I didn't need? Offhand I don't see it, do you recall what was missing? I'll unzip it to a new computer tomorrow and see if I can replicate a problem.

And please let us know if it works with Win7. I don't have access to it for tests.

Re: [VB6] XP/Vista Manifest Creator

1.It's a very good example of using Unicode (W-Type) APIs to Read/Write file.
2.It's a very good example to understand Resource File Structure.
3.It's a very good example to know how to put/retrieve UDT in a file.

Re: [VB6] XP/Vista Manifest Creator

Jonney, what is in the resfile is not a manifest, not really. A manifest file will have a RT_MANIFEST resource type. That text in the res file is a CUSTOM resource type. It might as well be an email or ini file. Even though it is a manifest, it will never effect a compiled application. One cannot just throw a manifest in a CUSTOM resource and have Windows recognize it as a true manifest. To read CUSTOM resource file entries or any resource entries, really, one simply needs to process all the resource types. The project I wrote only messes with RT_MANIFEST resource types.

Try creating a test project, one command button, adding that resfile & appropriate Startup code to the project and compiling it. The compiled project will not be themed if themes are active. Now add a manifest via this project, recompile, & it will be themed; your updated resfile will have 2 manifests in it: 1 that is a true manifest and one that is simply a custom, text resource.

The bottom line is that the code is fine. If the ReadFile API fails, it should set resDataL to zero, else it will set it to how many bytes were read. Anything <> 4, in this case, is considered failure.

Re: [VB6] XP/Vista/Win7 Manifest Creator

Hi,

When arriving to Step 5 and loading my project file it read the version as 6.2.35.0 while properties of my exe show 6.2.0.35 - is this correct? I know VB6 doesn't allow you to set one of the version parts, which should be 'build' as it has fileds for major, minor and revision and the MSDN docs (as linked above) refer to
the assembly version as 'major.minor.build.revision' so according to this MC have it wrong or?

Re: [VB6] XP/Vista/Win7 Manifest Creator

No problem, I mostly wanter to be sure about it but also it doesn'y seem to matter as at least the styles applies with both version strings.

But there is another reason as well, I have an Add-In vbAdvance that let me set this "zero masked" digit but in its documentation it refer to it as the revision and what VB6 call revision as build. I think they got it wrong though as according to the MSDN docs the 3rd integer is the build number.

Now that doesn't matter so much but what matter is that you may like to concider adding support for it rather then just hard code it to "0"?

Re: [VB6] XP/Vista/Win7 Manifest Creator

7edm, not possible. I did fix the version info issue & updated project in post #1 above. But a "Build" option is not available in a VBP file. Looking at your post above, VB does not have RevisionVersion it has RevisionVer. Trying to add RevisionVersion to a vbp file and opening in VB produces expected "invalid key" error.

Also note that what you may be looking at may not be a true VBP file, but rather a vbAdvanced file. From browsing the net, the only way to set the build number for an app is to do it after the fact; after compiled. I have no plans on modifying this for vbAdvanced files; but feel free to do so for your needs.

and so does the CodeSmart 2009 add-in which I also have, it's fully valid. Exactly how it then add that value to the exe file I don't know, but it does and it works. What I tried to explain above was that while VB and MSDN docs label that unaccessable value 'build', vbAccess refer to it as 'revision' and the other way around for the other. So the labels for the 2 positions are reversed.

But it's perfectly ok to keep it out of the project and anyone being in need of it (who uses vbAdvanced) can just patch with my code above, it works.

Re: [VB6] XP/Vista/Win7 Manifest Creator

I see. Yes, there is some inconsistency with what VB calls a revision and what .Net & others call revisions. The patch I put into place simply changed sVersion from "M.m.R.0" to "M.m.0.R". Tweaking the code to look for the additional vbAdvance section would be simple enough for those that use vbAdvance. And if so, do recommend using "M.m.B.R" as you stated, defaulting to zero for B if no such build information exists in the vbp file. Thanx for the vbAdvance lesson; never used that tool.

Re: [VB6] XP/Vista/Win7 Manifest Creator

Been away for a bit, but back now. Couple questions for verification
1. Your resource file, with the manifest in it, is referenced in your project?
-- Open it from inside your project and ensure you have a resource section named: 24
2. Did you tell your project to start with Sub Main? << I suspect this is the problem
3. If so, do you have themes applied in Vista?
4. If so, you are saying that none of the buttons, textboxes are themed? If they are, what exactly isn't themed?

Re: [VB6] XP/Vista/Win7 Manifest Creator

1. I believe so - I'm doing my tests with the Manfiest Creator project as downloaded - seems to have this
2. I believe so - I'm doing my tests with the Manfiest Creator project as downloaded - seems to do this
3. Err... Well I have a customised desk top - (wall paper) other than that is the standard vista theme as I understand it
4. Non, no buttons, no text boxes, no check boxes -it looks exactly as it did when first downloaded.

Re: [VB6] XP/Vista/Win7 Manifest Creator

Originally Posted by exgliderpilot

2. I believe so - I'm doing my tests with the Manfiest Creator project as downloaded - seems to do this

I am puzzled, thanks for the reply so far.

Ian

Manifest Creator doesn't do this, you have to do this with VB project properties.
See post #2 above, the section that starts with: "How to start your project with Sub Main?"
Also, ensure you have a Sub Main in a module as described in Post #2 above. Recommend re-reading Post #2 and follow its instructions exactly. Do not deviate.

Re: [VB6] XP/Vista/Win7 Manifest Creator

No apologies necessary. In order for the Manifest Creator to edit your project to force it to start with Sub Main, the creator would have to modify the .VBP file and/or create/modify a .BAS file. I chose not to automate it to that level -- too much effort, room for problems, for such little gain.

Re: [VB6] XP/Vista/Win7 Manifest Creator

Hi, Thanks for the reply - now I'm totaly confused...
here's what I see: http://creamteadiet.blogspot.com/201...confusion.html
and as i understand it that is the manifest creator project starting with sub main???
PS you may need to click on the image to get it full size...

Re: [VB6] XP/Vista/Win7 Manifest Creator

Oh good screenshot. I thought you were trying to apply a manifest to one of your projects, not the creator itself. The creator should be themed once it is compiled. Just so we are on the same page, recommend re-downloading the project from post #1 and just compile it; don't modify anything. Then open the compiled exe and see if it is themed. If not, we can discuss that.

To apply a manifest to one of your existing themes, use the steps in Post #2.

Re: [VB6] XP/Vista/Win7 Manifest Creator

For trivial manifests with little more than a CC6 selection assembly entry and a trustInfo entry you can edit them by hand using Notepad. Just be sure you pad the file to a multiple of 4 bytes as measured after saving them in UTF-8 format. Re-edit adding blank spaces to the end if required for padding.

Then you can add this as a Custom resource using VB6's Resource Editor, then edit the new resource's Properties to Type: #24 and Id: #1 as shown in the capture.

Re: [VB6] XP/Vista/Win7 Manifest Creator

Hi LaVolpe, Did as you asked - compliled exe has theme. So now I'm going to repeat applying the exe to the (newly) downloaded project. It may take a day or two as customer is rattling my cage over something else at this very moment. PS thanks for the help so far.

First I did like vbAdvance more, because it is possible to use a res file (I guess vbAcvance adds the manifest to that resource file before each compilation) - XP Style does not work, if a resource file is already added to the project.
But in one project, vbAcvance did make my application to crash at start up, when "adding XP manifest resource" was activated.

I'll bet you are able to bring all advantages together.
_______________________________________________

Something else:

If I add a manifest to my projects, which contain UserControls, they do all crash at program shut down, if I run them on other systems (Windows XP/Vista/7 wants to send an error report to Microsoft & executable cannot be deleted any more).
But it does not happen on my system (maybe because uxtheme.dll is patched... I have no clue ).

This already happens, if I start a new project with code to init common controls, add a resource file with included manifest and a new empty UserControl. Can you reproduce this behavior? Do you have any idea, how to solve this problem?

Re: [VB6] XP/Vista/Win7 Manifest Creator

I don't think it is hard to use. Just add a res file to your project and use this project or dilettante's method to insert a manifest into it. You can modify the project as needed to work with vbAdvance .vbw files. If vbAdvance can't remove an existing manifest from the res file, that is their shortcoming; you could use this project to remove the resfile though. I don't use vbAdvance and don't want to install it just to work around its shortcomings. I think you can understand. Take the time to modify the code and upload it here as a "vbAdvance-aware" version.

As for your other questions regarding the crashes & usercontrols, post that on the forum so more people can have opportunity to offer solutions from their experiences.

Re: [VB6] XP/Vista/Win7 Manifest Creator

Nice one LaVolpe

But am having a problem using the toolbar in v5sp2 of vb6. How do you make the regions of buttons in the tool bar control transparent. I am using magenta as the basckground color of my bitmap icon images. please check the attache. the issue occurs wjem you add manifest to project files

Re: [VB6] XP/Vista/Win7 Manifest Creator

Well, there are a few ways in this case

1) Non-traditional, simply select "Write Manifest" in the bottom combobox, after filling in the rest of the form. In the dialog box that pops up, select "Resource Files" in file type box, navigate to the folder of your project, provide a file name for the res file & click ok. The manifest creator creates the res file. You'll still need to add it to your project. See next step(s)