How to migrate a Visual C++ 6.0 custom AppWizard to a Visual C++ .NET custom wizard

Article translations Article translations
Article ID: 810455 - View products that this article applies to.
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SUMMARY

This article describes how to create a custom AppWizard in Visual C++ 6.0 and how to migrate the wizard to Visual C++ .NET.

INTRODUCTION

This step-by-step article describes how to migrate a Microsoft Visual C++ 6.0 custom AppWizard to a Microsoft Visual C++ .NET custom wizard. The custom wizard technology in Visual C++ .NET is significantly different from the custom AppWizard technology in Visual C++ 6.0. You cannot port a custom AppWizard project that was created in Visual C++ 6.0 directly to the new technology. However, you can reuse the existing template files and modify the existing directives to the new syntax.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
  • Microsoft Windows 2000 operating system or a later version
  • Microsoft Visual Studio 6.0
  • Microsoft Visual Studio .NET
This article assumes that you are familiar with the following topics:
  • Microsoft Visual Studio 6.0
  • Microsoft Visual Studio .NET
  • Microsoft Visual C++ .NET

Visual C++ 6.0 custom AppWizard

Create a Visual C++ 6.0 custom AppWizard

  1. Start Visual C++ 6.0.
  2. On the File menu, click New.

    The New dialog box appears.
  3. In the New dialog box, click the Projects tab.
  4. On the Projects tab, click Custom AppWizard.
  5. In the Project name box, type MyVC6Custom, and then click OK.

    The Custom AppWizard - Step 1 of 2 dialog box appears.
  6. Click Your own custom steps.
  7. In the How many custom steps would you like? box, set the number of custom steps to 0, click Finish, and then click OK.
A Custom AppWizard project that is named "MyVC6Custom" is created.


Create custom project files

  1. Start Notepad or a text editor application.
  2. In Notepad or in your text editor, paste the following code:
    #if !defined(AFX_STDAFX_H__6857DB3B_9305_41BF_BFB7_9DD42655FED5__INCLUDED_)
    #define AFX_STDAFX_H__6857DB3B_9305_41BF_BFB7_9DD42655FED5__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    #define WIN32_LEAN_AND_MEAN	
    
    #include <stdio.h>
    #include <conio.h>
    
    #endif
    
  3. Save the file as SAfx.h in the following folder:

    Path_to_VC6_Custom _AppWizard\MyVC6Custom\Template

    Note Path_to_VC6_Custom _AppWizard is a placeholder for the path where you created the MyVC6Custom project.
  4. In Notepad or in your text editor, paste the following code:
    #include "stdafx.h"
  5. Save the file as SAfx.cpp in the following folder:
    Path_to_VC6_Custom _AppWizard\MyVC6Custom\Template
  6. In Notepad or in your text editor, paste the following code:
    // Win32 Console Application: Defines the entry point for the console application.
    
    #include "stdafx.h"
    
    int main(int argc, char* argv[])
    {
    	printf("Hello World!\n");
    	getch();
    	return 0;
    }
  7. Save the file as Root.cpp in the following folder:
    Path_to_VC6_Custom _AppWizard\MyVC6Custom\Template

Customize the project

  1. Locate the following code in the MyVC6Customaw.cpp file of the MyVC6Custom project:
    void CMyVC6CustomAppWiz::CustomizeProject(IBuildProject* pProject)
    {
  2. Add the following code after the code that you located in step 1:
    CComPtr<IConfigurations> pConfigs;
    HRESULT hr=pProject->get_Configurations(&pConfigs);
    if(FAILED(hr))
    {
    	AfxMessageBox("An error occurred while obtaining the IConfigurations interface pointer");
    	return;
    }
    CComPtr<IConfiguration> pConfig;
    CComVariant index;
    VARIANT m_var = {0};
    CComBSTR Name;
    CString text;
    CString output;
    
    long Count=0;
    pConfigs->get_Count(&Count);
    
    // Iterate through all the configurations of the project.
    for(int i=1; i <= Count; i++)
    {
    	index=i;
    	hr=pConfigs->Item(index, &pConfig);
    	if(FAILED(hr))
    	{
    		AfxMessageBox("An error occurred while obtaining the IConfiguration pointer");
    		return;
    	}
    	pConfig->get_Name(&Name);
    	text = Name;
    	
    	if (text.Find("Debug") == -1)
    		output = "Release";
    	else
    		output = "Debug";
    
    	text.Format("/out:\"%s/%s.exe\"",output,m_Dictionary["Root"]);
    	pConfig->AddToolSettings(L"link.exe", text.AllocSysString(), m_var);
    	
    	pConfig->AddToolSettings(L"mfc", L"0", m_var);
    	pConfig->AddToolSettings(L"link.exe", L"/subsystem:console", m_var);
    	pConfig->AddToolSettings(L"link.exe", L"/incremental:yes", m_var);
    	pConfig->AddToolSettings(L"link.exe", L"/machine:I386", m_var);
    	
    	// Change the preprocessor definitions.
    	pConfig->AddToolSettings(L"cl.exe", L"/nologo", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/MLd", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/W3", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/Gm", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/ZI", m_var);	
    	pConfig->AddToolSettings(L"cl.exe", L"/Od", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/D \"WIN32\"", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/D \"_DEBUG\"", m_var);
    	pConfig->AddToolSettings(L"cl.exe", L"/D \"_CONSOLE\"", m_var); 
    
    	// Change the libraries.
    	pConfig->AddToolSettings(L"link.exe", L"kernel32.lib", m_var);
    	pConfig->AddToolSettings(L"link.exe", L"user32.lib", m_var);
    	
    	pConfig=NULL;
    }
    pConfigs=NULL;	
  3. Add the following code to the StdAfx.h file of the MyVC6Custom project:
    #include <atlbase.h>
    #include <ObjModel\bldguid.h> 
    #include <ObjModel\bldauto.h>

Copy the template files to the template directories

  1. In the Workspace window, click the FileView tab, right-click Template Files, and then click Add Files to Folder.

    The Insert Files into Project dialog box appears.
  2. In the Insert Files into Project dialog box, locate the following folder:
    Path_to_VC6_Custom _AppWizard\MyVC6Custom\Template
  3. Add the Root.cpp file, the SAfx.cpp file, and the SAfx.h file to the Template Files folder.
  4. In the Template Files folder, right-click Confirm.inf, click Open, and then replace the existing text in the Confirm.inf file with the following text:

    Simple Win32 console application.
    Prints "Hello, World!" to the console.
  5. In the Template Files folder, right-click Newproj.inf, click Open, and then replace the existing code in the Newproj.inf file with the following code:
    $$// newproj.inf = template for list of template files
    $$//  format is 'sourceResName' \t 'destFileName'
    $$//    The source res name may be preceded by any combination of '=', '-',  '!', '?', ':', '#', and/or '*'.
    $$//       '=' => the resource is binary
    $$//       '-' => the file should not be added to the project (all files are added to the project by default)
    $$//       '!' => the file should be marked exclude from build
    $$//       '?' => the file should be treated as a Help file
    $$//       ':' => the file should be treated as a resource
    $$//       '#' => the file should be treated as a template (implies '!')
    $$//       '*' => bypass the custom AppWizard's resources when loading
    $$//	if name starts with / => create new subdir
    
    
    +root.cpp	$$Root$$.cpp
    +SAfx.h	StdAfx.h
    +SAfx.cpp	StdAfx.cpp
    
    Note You must separate the file names by using the TAB key. Do not use the SPACEBAR.
  6. In the workspace, click the ResourceView tab, expand MyVC6Custom resources, right-click TEMPLATE, and then click Insert.

    The Insert Resource dialog box appears.
  7. In the Insert Resource dialog box, click Import.

    The Import Resource dialog box appears.
  8. In the Files of type box, click All Files (*.*), and then locate the following folder:
    Path_to_VC6_Custom _AppWizard\MyVC6Custom\Template
  9. Click Root.cpp, and then click Import.

    The Custom Resource Type dialog box appears.
  10. In the Custom Resource Type dialog box, click TEMPLATE, and then click OK.

    The IDR_TEMPLATE1 template is added to the TEMPLATE folder.
  11. Right-click IDR_TEMPLATE1, click Properties, type "ROOT.CPP" in the ID box, and then press ENTER.
  12. Repeat step 11 to add the SAfx.h file and the SAfx.cpp file to the TEMPLATE folder, and rename their ID properties to "SAFX.H" and "SAFX.CPP", respectively.
  13. On the File menu, click Save All.
  14. On the Build menu, click Rebuild All.
The MyVC6Custom AppWizard custom AppWizard is created. The MyVC6Custom AppWizard template is added to the Visual C++ Projects tab.


Visual C++ .NET custom wizard

Create a Visual C++ .NET custom wizard

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.
  3. Under Project Types, click Visual C++ Projects.
  4. Under Templates, click Custom Wizard.
  5. In the Name box, type MyVC7Custom, and then click OK.

    The Custom Wizard - MyVC7Custom dialog box appears.
  6. In the Custom Wizard - MyVC7Custom dialog box, click Application Settings, click to clear the User interface check box, and then click Finish.

Copy the template files to the template directories

  1. In Solution Explorer, expand all the folders.
  2. Right-click ReadMe.txt, and then click Remove.
  3. Move to the following folder:

    Path_to_VC6_Custom _AppWizard\MyVC6Custom\Templates
  4. Copy the Root.cpp file, the SAfx.cpp file, and the SAfx.h file to the Path_to_VC7_Custom _Wizard\MyVC7Custom\Templates\1041 folder

    NotePath_to_VC7_Custom _Wizard is a placeholder for the path where you created the MyVC7Custom wizard.
  5. Rename the SAfx.cpp file to StdAfx.cpp, and rename the SAfx.h file to StdAfx.h.
  6. Right-click Template Files, point to Add, and click Existing Item.
  7. The Add Existing Item - MyVC7Custom dialog box appears.
  8. In the Add Existing Item - MyVC7Custom dialog box, locate the following folder:

    Path_to_VC7_Custom _Wizard\MyVC7Custom\Templates\1041

    NotePath_to_VC7_Custom _Wizard is a placeholder for the path where you created the MyVC7Custom wizard.
  9. Add the Root.cpp file, the StdAfx.cpp file, and the StdAfx.h file to the Templates folder.

Customize the project

  1. In Solution Explorer, right-click Templates.inf, and then click Open.
  2. Replace the existing code with the following code:
    root.cpp
    StdAfx.cpp
    StdAfx.h
  3. In Solution Explorer, right-click default.js, and then click Open.
  4. Locate the following code in the Default.js file:
    function AddFilters(proj)
    {
  5. Replace the existing code in the AddFilters function that you located in step 4 with the following code:
    try
    {
    	// Add the folders to your project.
     var strSrcFilter1 = wizard.FindSymbol('SOURCE_FILTER');
    	var strSrcFilter2 = wizard.FindSymbol('HEADER_FILTER');
    	var strSrcFilter3 = wizard.FindSymbol('RESOURCE_FILTER');
    	
    	var group1 = proj.Object.AddFilter('Source Files');
    	var group2 = proj.Object.AddFilter('Header Files');
    	var group3 = proj.Object.AddFilter('Resource Files');
    	
    	group1.Filter = strSrcFilter1;
    	group2.Filter = strSrcFilter2;
    	group3.Filter = strSrcFilter3;
    }
    catch(e)
    {
    	throw e;
    }
    The AddFilters function specifies the source filters for the project.
  6. Locate the following code in the Default.js file:
    function AddConfig(proj, strProjectName)
    {
  7. Replace the existing code in the AddConfig function that you located in step 6 with the following code:
    try
    {
    	var config = proj.Object.Configurations('Debug');
    	config.IntermediateDirectory = 'Debug';
    	config.OutputDirectory = 'Debug';
    
    	var CLTool = config.Tools('VCCLCompilerTool');
    	CLTool.DebugInformationFormat = debugEnabled; 
    	CLTool.SuppressStartupBanner=true; 
    	CLTool.RuntimeLibrary=runtimeLibraryOption.rtMultiThreadedDebugDLL; 
    	CLTool.WarningLevel=warningLevelOption.warningLevel_3; 
    	CLTool.Optimization=optimizeOption.optimizeDisabled;
    	CLTool.MinimalRebuild=true;
    	CLTool.DebugInformationFormat=debugOption.debugEditAndContinue;
    	
    	var LinkTool = config.Tools('VCLinkerTool');
    	LinkTool.ProgramDatabaseFile = "$(outdir)/" + strProjectName + ".pdb"; 
    	LinkTool.GenerateDebugInformation = true;
    	LinkTool.LinkIncremental = linkIncrementalYes; 
    	LinkTool.OutputFile = "$(outdir)/" + strProjectName + ".exe";
    	LinkTool.SuppressStartupBanner=true;  // nologo
    	LinkTool.AdditionalDependencies="user32.lib";
    	LinkTool.AdditionalDependencies="kernel32.lib";
    
    	config = proj.Object.Configurations('Release');
    	config.IntermediateDirectory = 'Release';
    	config.OutputDirectory = 'Release';
    
    	var CLTool = config.Tools('VCCLCompilerTool');
    	// TODO: Add compiler settings.
    
    	var LinkTool = config.Tools('VCLinkerTool');
    	// TODO: Add linker settings.
    }
    catch(e)
    {
    	throw e;
    }
    The AddConfig function adds the project configurations. You can supply compiler and linker settings.
  8. Locate the following code in the Default.js file:
    function GetTargetName(strName, strProjectName)
    {
  9. Replace the existing code in the GetTargetName function that you located in step 8 with the following code:
    try
    {
    	var strTarget = strName;
    
    	if(strName == 'stdafx.h')
            strTarget = 'StdAfx.h';
    
        if(strName == 'stdafx.cpp')
            strTarget = 'StdAfx.cpp';
            
    	if(strName == 'root.cpp')
            strTarget = strProjectName + ".cpp";
    
    	return strTarget; 
    }
    catch(e)
    {
    	throw e;
    }
    The GetTargetName function gets the name of the specified file.
  10. In Solution Explorer, right-click MyVC7Custom.vsz, and then click Open.
  11. Locate the following code in the MyVC7Custom.vsz file:
    Param="SOURCE_FILTER = txt"
  12. Replace the code that you located in step 11 with the following code:
    Param="SOURCE_FILTER = cpp"
    Param="HEADER_FILTER = h"
    Param="RESOURCE_FILTER = txt"
  13. On the File menu, click Save All.
  14. Locate the following folder:
    Path_to_VC7_Custom _Wizard\MyVC7Custom
  15. Copy the MyVC7Custom.ico file, the MyVC7Custom.vsz file, and the MyVC7Custom.vsdir file to the following location:
    Hard disk drive\Microsoft Visual Studio .NET 2003\Vc7\vcprojects folder.
    Hard disk drive is a placeholder for the drive where Visual Studio .NET 2003 is installed.

    Note If you created the custom wizard in Microsoft Visual Studio .NET 2002, copy the MyVC7Custom.ico file, the MyVC7Custom.vsz file, and the MyVC7Custom.vsdir file to the following location:
    Hard disk drive\Microsoft Visual Studio .NET\Vc7\vcprojects folder.
    Hard disk drive is a placeholder for the drive where Visual Studio .NET 2002 is installed.
The MyVC7Custom custom wizard template is created. You can use the template to create a simple Win32 console application.

MORE INFORMATION

The VSZ file
The starting point for each wizard in Visual Studio .NET is the .vsz file. This .vsz file is a text file that determines what the wizard is named and what information is passed to the wizard. The file contains a two-line header followed by optional parameters that are passed to the wizard.

The VSDir file
A VSDir file is a text file with a .vsdir file name extension. The file provides information to the Add Item dialog box and the New Project dialog box about how to display the items that the file contains. These items include their names, the order that they appear, and the icon that is displayed with them. A single VSDir file contains records for multiple wizards, folders, and templates. Each record in the file is separated by a new line character. Pipe (|) characters separate the fields in each record.

The JScript file
Every custom wizard creates a JScript file that is named Default.js for each project. This file contains functions that you can use to customize your project. You can also add your own functions to the Default.js file for your project.

The Templates.inf file
The Templates.inf file is a text file that contains a list of templates for your project. You can use the template directives in the Templates.inf file to customize your project. Remember the following information when you use the template directives:
  • You cannot nest an [!if] directive in a [!loop] directive.
  • You can nest a [!loop] directive in another [!loop] directive or in [!if]/[!else] directives.
  • There is no [!elif] directive. You cannot nest [!if] directives in [!if]/[!else] directives. So for $$ELIF directives, you must duplicate the logic. For example, the following code is an example of an IF-ELSE loop that is created by using Visual C++ 6.0 template directives:
    $$IF (macro1)
    // Some code 1
    $$ELIF (macro2)
    // Some code 2
    $$ENDIF

    This code can be converted to the following code according to Visual C++ .NET template directives:
    [!if macro1]
    // Some code 1
    [!endif]
    [!if !macro1 and macro2]
    // Some code 2
    [!endif]
  • You can specify comments by using the following example:
    [!if 0]
    This is a comment.
    [!endif]


REFERENCES

For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
Creating Custom AppWizards
http://msdn2.microsoft.com/en-us/library/Aa293241(VS.60).aspx
Designing a Wizard
http://msdn2.microsoft.com/en-us/library/96xz4cw2(vs.71).aspx
Handling Errors in Wizards
http://msdn2.microsoft.com/en-us/library/ecbx59y8(vs.71).aspx
Visual C++ Project Model
http://msdn2.microsoft.com/en-us/library/2eydyk57(vs.71).aspx
Migrating Custom Wizards from Visual C++ .NET 2002 to Visual C++ .NET 2003
http://msdn2.microsoft.com/en-us/library/8278bkdc(vs.71).aspx


Properties

Article ID: 810455 - Last Review: January 17, 2015 - Revision: 2.8
APPLIES TO
  • Microsoft Visual Studio .NET 2003 Professional Edition
  • Microsoft Visual Studio .NET 2003 Enterprise Architect
  • Microsoft Visual Studio .NET 2003 Enterprise Developer
  • Microsoft Visual Studio .NET 2003 Academic Edition
  • Microsoft Visual Studio .NET 2002 Professional Edition
  • Microsoft Visual Studio .NET 2002 Enterprise Architect
  • Microsoft Visual Studio .NET 2002 Enterprise Developer
  • Microsoft Visual Studio .NET 2002 Academic Edition
Keywords: 
kbnosurvey kbarchive kbhowtomaster kbwizard kbideproject kbide kbcustomwizard kbappwizard kbmigrate kbenv kbcodegen kbhowto KB810455

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com