Code Gem

Code Gem

Knowledge was arriving in dribs and drabs

Code Gem RSS Feed
 
 
 
 

WTL Wizard for Visual Studio 2008

WTLAh … I realized that this is going to be the first post in my blog … wow!

While the latest version of WTL was released last year, it was updated with whole bunch of Vista support.  One thing that is really painful using non-MFC UI framework before is that there doesn’t have a good IDE support. A good news is that WTL 8.0 released with application wizards for both Visual C++ and Visual C++ Express. As easy as with MFC, a default project is created just with several mouse clicks.

wtlwizard

It is very easy to install the wizard. After the WTL package is unzipped, there is a folder named ‘AppWiz’. Under which there are some javascript files for installing the wizard automatically. You only need to pick proper script for the different version of Visual Studio you installed. All easy shots. While this is very nice but one last minor issue is that at that time Visual Studio 2008 has not been released yet. Thus there is no install script for Visual Studio 2008.

I poked around internet and saw some people asking the question here and there. Actually the solution is pretty straight forward: open ‘setup80.js’ and edit it with notepad. Correct any registry key as if they are in Visual Studio 2008. Save it back, run it and you should be all set.

If you do not want to modify the script yourself, here is the code code I modified. Copy the code and save it at %WTL%\AppWiz\setup90.js. If you are in Vista, make sure you run it as Administrator. You are using the code at your own risk. No warrant is promised or implied by CodeGem.org.

// Windows Template Library - WTL version 8.0
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// This file is a part of the Windows Template Library.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/osi3.0/licenses/cpl1.0.php)
// which can be found in the file CPL.TXT at the root of this distribution.
// By using this software in any fashion, you are agreeing to be bound by
// the terms of this license. You must not remove this notice, or
// any other, from this software.

// Setup program for the WTL App Wizard for VC++ 9.0 (Orcas)

main();

function main()
{
	// Decode command line arguments
	var bDebug = false;
	var bElevated = false;
	var Args = WScript.Arguments;
	for(var i = 0; i < Args.length; i++)
	{
		if(Args(i) == "/debug")
			bDebug = true;
		else if(Args(i) == "/elevated")
			bElevated = true;
	}

	// See if UAC is enabled
	var Shell = WScript.CreateObject("Shell.Application");
	if(!bElevated && Shell.IsRestricted("System", "EnableLUA"))
	{
		// Check that the script is being run interactively.
		if(!WScript.Interactive)
		{
			WScript.Echo("ERROR: Elevation required.");
			return;
		}

		// Now relaunch the script, using the "RunAs" verb to elevate
		var strParams = "\"" + WScript.ScriptFullName + "\"";
		if (bDebug)
			strParams += " /debug";
		strParams += " /elevated";
		Shell.ShellExecute(WScript.FullName, strParams, null, "RunAs");
		return;
	}

	// Create shell object
	var WSShell = WScript.CreateObject("WScript.Shell");
	// Create file system object
	var FileSys = WScript.CreateObject("Scripting.FileSystemObject");

	// Get the folder containing the script file
	var strValue = FileSys.GetParentFolderName(WScript.ScriptFullName);
	if(strValue == null || strValue == "")
		strValue = ".";

	var strSourceFolder = FileSys.BuildPath(strValue, "Files");
	if(bDebug)
		WScript.Echo("Source: " + strSourceFolder);

	if(!FileSys.FolderExists(strSourceFolder))
	{
		WScript.Echo("ERROR: Cannot find Wizard folder (should be: " + strSourceFolder + ")");
		return;
	}

	try
	{
		var strVC9Key = "HKLM\\Software\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
		strValue = WSShell.RegRead(strVC9Key);
	}
	catch(e)
	{
		try
		{
			var strVC9Key_x64 = "HKLM\\Software\\Wow6432Node\\Microsoft\\VisualStudio\\9.0\\Setup\\VC\\ProductDir";
			strValue = WSShell.RegRead(strVC9Key_x64);
		}
		catch(e)
		{
			WScript.Echo("ERROR: Cannot find where Visual Studio 9.0 is installed.");
			return;
		}
	}

	var strDestFolder = FileSys.BuildPath(strValue, "vcprojects");
	if(bDebug)
		WScript.Echo("Destination: " + strDestFolder);
	if(!FileSys.FolderExists(strDestFolder))
	{
		WScript.Echo("ERROR: Cannot find destination folder (should be: " + strDestFolder + ")");
		return;
	}

	// Copy files
	try
	{
		var strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.ico");
		var strDest = FileSys.BuildPath(strDestFolder, "WTLAppWiz.ico");
		FileSys.CopyFile(strSrc, strDest);

		strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.vsdir");
		strDest = FileSys.BuildPath(strDestFolder, "WTLAppWiz.vsdir");
		FileSys.CopyFile(strSrc, strDest);
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot copy file (" + strError + ")");
		return;
	}

	// Read and write WTLAppWiz.vsz, add engine version and replace path when found
	try
	{
		var strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.vsz");
		var strDest = FileSys.BuildPath(strDestFolder, "WTLAppWiz.vsz");

		var ForReading = 1;
		var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
		if(fileSrc == null)
		{
			WScript.Echo("ERROR: Cannot open source file " + strSrc);
			return;
		}

		var ForWriting = 2;
		var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
		if(fileDest == null)
		{
			WScript.Echo("ERROR: Cannot open destination file" + strDest);
			return;
		}

		while(!fileSrc.AtEndOfStream)
		{
			var strLine = fileSrc.ReadLine();
			if(strLine.indexOf("Wizard=VsWizard.VsWizardEngine") != -1)
				strLine += ".9.0";
			else if(strLine.indexOf("WIZARD_VERSION") != -1)
				strLine = "Param=\"WIZARD_VERSION = 9.0\"";
			else if(strLine.indexOf("ABSOLUTE_PATH") != -1)
				strLine = "Param=\"ABSOLUTE_PATH = " + strSourceFolder + "\"";
			fileDest.WriteLine(strLine);
		}

		fileSrc.Close();
		fileDest.Close();
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot read and write WTLAppWiz.vsz (" + strError + ")");
		return;
	}

	// Create WTL folder
	var strDestWTLFolder = "";
	try
	{
		strDestWTLFolder = FileSys.BuildPath(strDestFolder, "WTL");
		if(!FileSys.FolderExists(strDestWTLFolder))
			FileSys.CreateFolder(strDestWTLFolder);
		if(bDebug)
			WScript.Echo("WTL Folder: " + strDestWTLFolder);
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot create WTL folder (" + strError + ")");
		return;
	}

	// Read and write additional WTLAppWiz.vsdir, add path to the wizard location
	try
	{
		var strSrc = FileSys.BuildPath(strSourceFolder, "WTLAppWiz.vsdir");
		var strDest = FileSys.BuildPath(strDestWTLFolder, "WTLAppWiz.vsdir");

		var ForReading = 1;
		var fileSrc = FileSys.OpenTextFile(strSrc, ForReading);
		if(fileSrc == null)
		{
			WScript.Echo("ERROR: Cannot open source file " + strSrc);
			return;
		}

		var ForWriting = 2;
		var fileDest = FileSys.OpenTextFile(strDest, ForWriting, true);
		if(fileDest == null)
		{
			WScript.Echo("ERROR: Cannot open destination file" + strDest);
			return;
		}

		while(!fileSrc.AtEndOfStream)
		{
			var strLine = fileSrc.ReadLine();
			if(strLine.indexOf("WTLAppWiz.vsz|") != -1)
				strLine = "..\\" + strLine;
			fileDest.WriteLine(strLine);
		}

		fileSrc.Close();
		fileDest.Close();
	}
	catch(e)
	{
		var strError = "no info";
		if(e.description.length != 0)
			strError = e.description;
		WScript.Echo("ERROR: Cannot read and write WTL\\WTLAppWiz.vsdir (" + strError + ")");
		return;
	}

	WScript.Echo("App Wizard successfully installed!");
}


Enjoy!

Share/Save/Bookmark

17 Responses to “WTL Wizard for Visual Studio 2008”

  1. 1
    Paul:

    Finally I got your first blog. Keep contribution to the world :)

  2. 2
    Barry:

    Where exactly do I put the AppWiz folder? I’m developing for Win Mobile, so where should I copy the AppWizMobile folder? Thanks for your help!!

  3. 3
    ThinkQuad:

    View the code and copy the code by yourself.
    Do NOT be lazy and click the “copy to clipboard” link. By that link, all ‘<’ in the code will be changed to ‘<’, which makes the js invalid.

  4. 4
    ThinkQuad:

    oh, it changes back to ‘<’, I meant ‘& l t ;’, which is html code.

  5. 5
    Mike Russell:

    Thanks - this script saved me a bunch of time!

    Also, knowing that WTL 8.0 works with VS 2008 was also very helpful, as this is not documented anywhere that I could find.

  6. 6
    Slobodan:

    Thank you,
    your post is highly ranked on google for “wtl vs 2008″
    now I can migrate to vs2008

  7. 7
    Aneesh Abraham:

    Hi , I found this article helpful.

    I am trying to make a project in VS 2005 as well as vs 2008 for Smart device.
    My requirement is to call a webservice from managed C++.
    After alot of search , i came to know about WTL Mobile application Wizard and downloaded WTL 8.0.
    clicking on the .js file , was a sucess.

    The issue is that I have the WTL Mobile application Wizard availabel as a template but after naming the project and clicking Ok , I a getting a message that Project creation is failed.

    Can you help me with this?

  8. 8
    Max:

    Sounds great but you don’t mention any ATL specs. I’m having ATL dependency trouble getting WTL up. It may be the wrong version?

  9. 9
    Joe:

    I have exactly the same problem - missing ATL dependency.
    Does anybody know how to solve this problem?

  10. 10
    Dex:

    It looks like there is no ATL with the included libraries/PSDK that comes with VC8 Express. You may have to grab a previous version ATL from an old PSDK, to get WTL working.

    Kind of a pain considering ATL was once available with the PSDK….
    It seems like MSFT hinted at including latest version of ATL in future releases…. but still nothing.

  11. 11
    Peter:

    I tried it, but received the error ‘cannot find where visual studio 9.0 is installed’.

  12. 12
    mnjrupp:

    I also received the same error as Peter.
    Is there an update on this script?
    Thanks

  13. 13
    mnjrupp:

    I replaced VisualStudio with VCExpress in the script and it works!

    Thanks!

  14. 14
    Lev Elbert:

    During deploiment of WTL80 I ran into a few problems.

    VS2008 SP1 - inittially I replaced in AppWiz\setup80.js only REGISTRY related “8.0″ with “9.0″.
    Wrong! The wizard was not writing anything after pressing the “Finish” button.
    Replace ALL “8.0″ with “9.0″ and all will be kosher!

    VC2009x - - inittially I replaced in AppWiz\setup80x.js only REGISTRY related “8.0″ with “9.0″.
    Wrong! The WTL wizard is on the list but pressing OK in the “New Project” dialog just closes the dialog and dosen’t open “ATL/WTL application wizard”.
    Replace ALL “8.0″ with “9.0″ and all will be kosher!

    And then the “default” (i.e. with no changes) project does not build,because it is missing WTL dependancies.
    I have WTL installed in C:\WTL80. Modify Project Properties:
    1. In “C++/General/Adittional Include Directories” enter C:\WTL80\include
    2. In “Resources/General/Adittional Include Directories” ADD C:\WTL80\include

    To link I also had _ATL_DLL to “C++/Preprocessor/Preprocessor Definitions”

    Now enjoy!

  15. 15
    Srinivas:

    For VS 2008, Apart from modifying registry entries and executing the install script - Modify

    \Program Files\Microsoft Visual Studio 9.0\VC\vcprojects\WTLAppWiz.vsz

    for the following

    Wizard=VsWizard.VsWizardEngine.9.0

    Restart VS 2008, and Wizard works.

  16. 16
    adipiciu:

    The latest WTL from sourceforge is version WTL81_9127 from May 07 2009. You don’t need to modify the install anymore. Anyway, thanks for the article!

  17. 17
    lofrank:

    Thank you,it’s helpful.

Leave a Reply

March 2010
M T W T F S S
« Feb «-»  
1234567
891011121314
15161718192021
22232425262728
293031  

Blogroll