Click here to Skip to main content
15,896,154 members
Articles / Programming Languages / C++

Understanding Classic COM Interoperability With .NET Applications

Rate me:
Please Sign up or sign in to vote.
4.96/5 (207 votes)
24 Jul 2001 1.3M   11.9K   715  
Discusses how existing COM components can be used from managed code.
using System;
using System.Collections;

public class SevenDwarfs : IEnumerable , IEnumerator
{
	private int nCurrentPos = -1;
	private string[] strArrayDwarfs =  new String[7] {"Doc", "Dopey", "Happy", "Grumpy",
									                  "Sleepy", "Sneezy" , "Bashful"};

    SevenDwarfs() {}
	
	// Method : IEnumerable.GetEnumerator
	// Return an appropriate Enumerator for the collection
	public IEnumerator GetEnumerator() 
	{
		return (IEnumerator)this;
	}
	
	// Method : IEnumerator.MoveNext
	// Move the enumerator to the next element in the collection
	// and return boolean status whether we still have elements to 
	// enumerate
	public bool MoveNext() 
	{
		if(nCurrentPos < strArrayDwarfs.Length - 1)
		{
		   nCurrentPos++;
		   return true;
		}
		else
		{
		   return false;
		}
	}
	
	// Method : IEnumerator.Reset
	// Reset the enumerator to the beginning of the collection
	public void Reset()
	{
		nCurrentPos = -1;
	}

	// Method : IEnumerator.Current
	// Return the element at the current enumerator position
	public object Current
	{
		get
		{
		  return strArrayDwarfs[nCurrentPos];
		}
	}

	public static void Main(String[] args)
	{
		// Create an instance of the SevenDwarfs object
		SevenDwarfs SnowWhitesDwarfs = new SevenDwarfs();

		// Enumerate through the Collection
		foreach(string dwarf in SnowWhitesDwarfs)
		{
           System.Console.WriteLine("{0}",dwarf);
		}

	}/* end Main */
    
}/* end class SevenDwarfs */

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
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions