Microsoft KB Archive/810455

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

Article ID: 810455

Article Last Modified on 11/13/2007

-

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

-



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.



IN THIS TASK

 * INTRODUCTION
 * Requirements
 * Visual C++ 6.0 custom AppWizard
 * Create a Visual C++ 6.0 custom AppWizard
 * Create custom project files
 * Customize the project
 * Copy the template files to the template directories
 * Visual C++ .NET custom wizard
 * Create a Visual C++ .NET custom wizard
 * Copy the template files to the template directories
 * Customize the project
 * More Information
 * REFERENCES



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.

back to the top

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

back to the top

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.
 * 1) In the New dialog box, click the Projects tab.
 * 2) On the Projects tab, click Custom AppWizard.
 * 3) In the Project name box, type MyVC6Custom, and then click OK.

The Custom AppWizard - Step 1 of 2 dialog box appears.
 * 1) Click Your own custom steps.
 * 2) 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 &quot;MyVC6Custom&quot; is created.

back to the top

Create custom project files
 Start Notepad or a text editor application.  In Notepad or in your text editor, paste the following code:
 * 1) if !defined(AFX_STDAFX_H__6857DB3B_9305_41BF_BFB7_9DD42655FED5__INCLUDED_)
 * 2) define AFX_STDAFX_H__6857DB3B_9305_41BF_BFB7_9DD42655FED5__INCLUDED_


 * 1) if _MSC_VER > 1000
 * 2) pragma once
 * 3) endif // _MSC_VER > 1000


 * 1) define WIN32_LEAN_AND_MEAN


 * 1) include 
 * 2) include 

Save the file as SAfx.h in the following folder:
 * 1) endif 

\MyVC6Custom\Template

Note is a placeholder for the path where you created the MyVC6Custom project.  In Notepad or in your text editor, paste the following code: Save the file as SAfx.cpp in the following folder:
 * 1) include &quot;stdafx.h&quot; 

\MyVC6Custom\Template

  In Notepad or in your text editor, paste the following code:

// Win32 Console Application: Defines the entry point for the console application.


 * 1) include &quot;stdafx.h&quot;

int main(int argc, char* argv[]) {   printf(&quot;Hello World!\n&quot;); getch; return 0; } </li> Save the file as Root.cpp in the following folder:

\MyVC6Custom\Template</li></ol>

back to the top

Customize the project
<ol>  Locate the following code in the MyVC6Customaw.cpp file of the MyVC6Custom project: void CMyVC6CustomAppWiz::CustomizeProject(IBuildProject* pProject) { </li>  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(&quot;An error occurred while obtaining the IConfigurations interface pointer&quot;); 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(&quot;An error occurred while obtaining the IConfiguration pointer&quot;); return; }   pConfig->get_Name(&Name); text = Name; if (text.Find(&quot;Debug&quot;) == -1) output = &quot;Release&quot;; else output = &quot;Debug&quot;;

text.Format(&quot;/out:\&quot;%s/%s.exe\&quot;&quot;,output,m_Dictionary[&quot;Root&quot;]); pConfig->AddToolSettings(L&quot;link.exe&quot;, text.AllocSysString, m_var); pConfig->AddToolSettings(L&quot;mfc&quot;, L&quot;0&quot;, m_var); pConfig->AddToolSettings(L&quot;link.exe&quot;, L&quot;/subsystem:console&quot;, m_var); pConfig->AddToolSettings(L&quot;link.exe&quot;, L&quot;/incremental:yes&quot;, m_var); pConfig->AddToolSettings(L&quot;link.exe&quot;, L&quot;/machine:I386&quot;, m_var); // Change the preprocessor definitions. pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/nologo&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/MLd&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/W3&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/Gm&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/ZI&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/Od&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/D \&quot;WIN32\&quot;&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/D \&quot;_DEBUG\&quot;&quot;, m_var); pConfig->AddToolSettings(L&quot;cl.exe&quot;, L&quot;/D \&quot;_CONSOLE\&quot;&quot;, m_var);

// Change the libraries. pConfig->AddToolSettings(L&quot;link.exe&quot;, L&quot;kernel32.lib&quot;, m_var); pConfig->AddToolSettings(L&quot;link.exe&quot;, L&quot;user32.lib&quot;, m_var); pConfig=NULL; } pConfigs=NULL; </li>  Add the following code to the StdAfx.h file of the MyVC6Custom project:
 * 1) include <atlbase.h>
 * 2) include <ObjModel\bldguid.h>
 * 3) include <ObjModel\bldauto.h> </li></ol>

back to the top

Copy the template files to the template directories
<ol> 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.</li> In the Insert Files into Project dialog box, locate the following folder:

\MyVC6Custom\Template</li> Add the Root.cpp file, the SAfx.cpp file, and the SAfx.h file to the Template Files folder.</li> 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 &quot;Hello, World!&quot; to the console.</li>  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. </li> In the workspace, click the ResourceView tab, expand MyVC6Custom resources, right-click TEMPLATE, and then click Insert.

The Insert Resource dialog box appears.</li> In the Insert Resource dialog box, click Import.

The Import Resource dialog box appears.</li> In the Files of type box, click All Files (*.*), and then locate the following folder:

\MyVC6Custom\Template</li> Click Root.cpp, and then click Import.

The Custom Resource Type dialog box appears.</li> In the Custom Resource Type dialog box, click TEMPLATE, and then click OK.

The IDR_TEMPLATE1 template is added to the TEMPLATE folder.</li> Right-click IDR_TEMPLATE1, click Properties, type &quot;ROOT.CPP&quot; in the ID box, and then press ENTER.</li> <li>Repeat step 11 to add the SAfx.h file and the SAfx.cpp file to the TEMPLATE folder, and rename their ID properties to &quot;SAFX.H&quot; and &quot;SAFX.CPP&quot;, respectively.</li> <li>On the File menu, click Save All.</li> <li>On the Build menu, click Rebuild All.</li></ol>

The MyVC6Custom AppWizard custom AppWizard is created. The MyVC6Custom AppWizard template is added to the Visual C++ Projects tab.

back to the top

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.
 * 1) Under Project Types, click Visual C++ Projects.
 * 2) Under Templates, click Custom Wizard.
 * 3) In the Name box, type MyVC7Custom, and then click OK.

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

back to the top

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:

\MyVC6Custom\Templates
 * 1) Copy the Root.cpp file, the SAfx.cpp file, and the SAfx.h file to the  \MyVC7Custom\Templates\1041 folder

Note is a placeholder for the path where you created the MyVC7Custom wizard.
 * 1) Rename the SAfx.cpp file to StdAfx.cpp, and rename the SAfx.h file to StdAfx.h.
 * 2) Right-click Template Files, point to Add, and click Existing Item.
 * 3) The Add Existing Item - MyVC7Custom dialog box appears.
 * 4) In the Add Existing Item - MyVC7Custom dialog box, locate the following folder:

\MyVC7Custom\Templates\1041

Note is a placeholder for the path where you created the MyVC7Custom wizard.
 * 1) Add the Root.cpp file, the StdAfx.cpp file, and the StdAfx.h file to the Templates folder.

back to the top

Customize the project
<ol> <li>In Solution Explorer, right-click Templates.inf, and then click Open.</li> <li> Replace the existing code with the following code:

root.cpp StdAfx.cpp StdAfx.h </li> <li>In Solution Explorer, right-click default.js, and then click Open.</li> <li> Locate the following code in the Default.js file: function AddFilters(proj) { </li> <li> 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. </li> <li> Locate the following code in the Default.js file:

function AddConfig(proj, strProjectName) { </li> <li> 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 = &quot;$(outdir)/&quot; + strProjectName + &quot;.pdb&quot;; LinkTool.GenerateDebugInformation = true; LinkTool.LinkIncremental = linkIncrementalYes; LinkTool.OutputFile = &quot;$(outdir)/&quot; + strProjectName + &quot;.exe&quot;; LinkTool.SuppressStartupBanner=true; // nologo LinkTool.AdditionalDependencies=&quot;user32.lib&quot;; LinkTool.AdditionalDependencies=&quot;kernel32.lib&quot;;

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. </li> <li> Locate the following code in the Default.js file: function GetTargetName(strName, strProjectName) { </li> <li> 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 + &quot;.cpp&quot;;

return strTarget; } catch(e) {   throw e; } The GetTargetName function gets the name of the specified file. </li> <li>In Solution Explorer, right-click MyVC7Custom.vsz, and then click Open.</li> <li> Locate the following code in the MyVC7Custom.vsz file:

Param=&quot;SOURCE_FILTER = txt&quot; </li> <li> Replace the code that you located in step 11 with the following code: Param=&quot;SOURCE_FILTER = cpp&quot; Param=&quot;HEADER_FILTER = h&quot; Param=&quot;RESOURCE_FILTER = txt&quot; </li> <li>On the File menu, click Save All.</li> <li>Locate the following folder:

\MyVC7Custom

</li> <li>Copy the MyVC7Custom.ico file, the MyVC7Custom.vsz file, and the MyVC7Custom.vsdir file to the following location:

\Microsoft Visual Studio .NET 2003\Vc7\vcprojects folder.

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:

\Microsoft Visual Studio .NET\Vc7\vcprojects folder.

is a placeholder for the drive where Visual Studio .NET 2002 is installed.</li></ol>

The MyVC7Custom custom wizard template is created. You can use the template to create a simple Win32 console application.

back to the top

<div class="moreinformation_section">

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: <ul> <li>You cannot nest an [!if] directive in a [!loop] directive.</li> <li>You can nest a [!loop] directive in another [!loop] directive or in [!if]/[!else] directives.</li> <li> 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] </li> <li> You can specify comments by using the following example:

[!if 0]

This is a comment.

[!endif] </li></ul>

back to the top

<div class="references_section">