我正在尝试为Visual Studio 2012创建一个New Item Wizard。这将是一个创建多个C ++文件并将它们添加到项目的向导。我为VS 2005创建了一个类似的向导。我试图使用IDTWizard接口创建它。我按照这个演练:http://msdn.microsoft.com/en-us/library/7k3w6w59(v=vs.110).aspx
当我尝试使用向导时,我收到一条错误消息,指出"在文档顶层无效"。当我查看oleview.exe显示的数据时,我的dll显示为已注册的COM对象。我究竟做错了什么?我是否应该像使用html / javascript创建VS2005向导一样进行操作?我的代码如下:
Wizard.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SystemsModuleWizard
{
[ComVisible(true)]
[Guid("FE7DC545-30DC-445B-8130-897C5F3114EC"), ProgId("SystemsModuleWizard.WizardClass")]
public class WizardClass : IDTWizard
{
public void Execute(object Application,
int hwndOwner, ref object[] contextParams,
ref object[] customParams,
ref EnvDTE.wizardResult retval)
{
MessageBox.Show("The wizard is running");
}
}
}
的AssemblyInfo.cs:
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SystemsModuleWizard")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SystemsModuleWizard")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ab29b7df-32c4-4dca-ade4-a31f687b9331")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
答案 0 :(得分:0)
我注意到您的Execute
实施是:
public void Execute(object Application,
int hwndOwner, ref object[] contextParams,
ref object[] customParams,
ref EnvDTE.wizardResult retval)
{
MessageBox.Show("The wizard is running");
}
但根据this MSDN page,retval
是out
参数,而不是ref
参数:
void Execute(
Object Application,
int hwndOwner,
ref Object[] ContextParams,
ref Object[] CustomParams,
out wizardResult retval
)
您链接的演练肯定会将其作为ref
,但也许这是一个错误。我不知道两者是如何工作的 - 内存分配和编组会有所不同。试试看。希望这会有所帮助。
答案 1 :(得分:0)
我对此很感兴趣,所以我按照链接演练中的步骤敲了一个快速向导。但它运作良好:
(事实证明ref
或out
param的问题并未出现,因为它甚至无法使用out
进行编译。所以{{3将它作为out
提供是完全错误的。)
所以我开始看看如何打破它。
以下是:如何在.vsz
文件中引入错误,。例如,如果您的文件包含行
VSWIZARD 7.0
Wizard=MyNewWizard.Class1
Param=First Item
Param=Second Item
错误拼写第二行中的类名:
Wizard=ThyNewWizard.Class1
当我这样做时,它肯定会显示您的错误消息:
由于您已检查过您的课程已在COM注册,因此您的.vsz
文件中可能会出现拼写错误等。