Click here to Skip to main content
15,891,513 members
Articles / Programming Languages / Javascript

A COM class wizard for VS.NET 2003

Rate me:
Please Sign up or sign in to vote.
4.67/5 (40 votes)
15 Aug 20046 min read 165.1K   2.3K   59  
A wizard to bring easy COM class creation to C#.
// (c) Microsoft Corporation
// modified by Martin M�ller

function OnFinish(selProj, selObj)
{
	try
	{
		var strTarget = wizard.FindSymbol("ITEM_NAME");
		var strClassName = strTarget.split(".");
		var bValid = wizard.ValidateCLRIdentifier(strClassName[0]);
		if (!bValid)
		{
			wizard.ReportError();
			return VS_E_WIZARDBACKBUTTONPRESS;
		}
		var strProjectName 	= wizard.FindSymbol("PROJECT_NAME");
		var strSafeProjectName 	= CreateSafeName(strProjectName);
		wizard.AddSymbol("SAFE_PROJECT_NAME", strSafeProjectName);
		SetTargetFullPath(selObj);
		var strProjectPath	= wizard.FindSymbol("TARGET_FULLPATH");

		wizard.AddSymbol("CLASS_NAME", strClassName[0]);
		wizard.AddSymbol("INTERFACE_NAME", "I"+strClassName[0]);
		wizard.AddSymbol("EVENTS_NAME", "I"+strClassName[0]+"Events");

		// GUIDS
		var strRawGuid = wizard.CreateGuid();
		wizard.AddSymbol("GUID_COCLASS", wizard.FormatGuid(strRawGuid, 0));
		strRawGuid = wizard.CreateGuid();
		wizard.AddSymbol("GUID_INTERFACE", wizard.FormatGuid(strRawGuid, 0));
		strRawGuid = wizard.CreateGuid();	
		wizard.AddSymbol("GUID_EVENTS", wizard.FormatGuid(strRawGuid, 0));

		var InfFile = CreateInfFile();

		AddReferencesForClass(selProj);
		AddFilesToCSharpProject(selObj, strProjectName, strProjectPath, InfFile, true);
				
		// Alle Konfigurationen so festlegen, dass das Element f�r COM-Interop registriert wird
		var configs = new Enumerator(selProj.ConfigurationManager);
		for(;!configs.atEnd();configs.moveNext())
		{
			configs.item().Properties("RegisterForComInterop").Value = 1;
		}
	}
	catch(e)
	{
		if( e.description.length > 0 )
			SetErrorInfo(e);
		return e.number;
	}
	finally
	{
		if( InfFile )
			InfFile.Delete();
	}
}

function SetFileProperties(oFileItem, strFileName)
{
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) 4voice AG
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions