Click here to Skip to main content
12,503,681 members (53,009 online)
Click here to Skip to main content

Stats

980.3K views
10.8K downloads
700 bookmarked
Posted

Understanding Classic COM Interoperability With .NET Applications

, 24 Jul 2001
Discusses how existing COM components can be used from managed code.
COMInteropWithDOTNET
COMInteropWithDOTNETDemo
AirlineNotifyMetadata.dll
AirlineMetadata.dll
SevenDwarfs.exe
IceCreamMenuClient.exe
HelloWorldDelegate.exe
FlightClient.exe
DelegateTest.exe
AirlineNotifyClient.exe
WeatherNotify.dll
AirlineInformation.dll
AirlineNotify.exe
IceCreamParlor.dll
MyFlyer.dll
NETThreadDemoClient.exe
ControlTower.exe
VBIceCreamProject.dll
VBTestClient.exe
VBWeatherStation.exe
AirlineClient.exe
Temperature.dll
MyFlyerMetadata.dll
IceCreamMenuMetadata.dll
HelloDotNet.dll
Directional.dll
COMInteropWithDOTNETSource
DOTNET-CSharpFiles
MyKeyPair.snk
AirlineInformation.tlb
IceCreamParlor.tlb
AirlineNotify.tlb
MyFlyer.tlb
ClassicCOM
AirlineNotify
AirlineNotifyps.def
AirlineNotifyps.mk
AirlineNotify.rgs
AirlineNotify.dsw
AirlineArrivalPager.rgs
AirlineNotify.aps
AirlineNotify.dsp
AirlineNotify.suo
AirlineNotify.tlb
AirlineNotify.opt
AirlineInformation
AirlineInfo.rgs
AirlineInformation.aps
AirlineInformation.def
AirlineInformationps.def
AirlineInformationps.mk
AirlineInformation.dsp
AirlineInformation.dsw
AirlineInformation.tlb
AirlineInformation.opt
VBIceCreamParlor
IceCreamMenu.cls
stdole.dll
VBIceCreamProject.vbw
VBIceCreamProject.lib
VBIceCreamProject.exp
VBIceCreamProject.vbp
VBAirlineControlTower
MainForm.frm
ControlTower.vbw
ControlTower.vbp
IceCreamParlor
IceCreamMenu.rgs
IceCreamParlor.def
IceCreamParlor.aps
IceCreamParlorps.def
IceCreamParlorps.mk
IceCreamParlor.dsp
IceCreamParlor.dsw
IceCreamParlor.tlb
IceCreamParlor.opt
MyFlyer
MyFlyer.dsp
MyFlyer.def
MyFlyerps.def
MyFlyerps.mk
MyFlyer.dsw
Flyer.rgs
MyFlyer.aps
MyFlyer.tlb
MyFlyer.opt
VBTestClient
VBTestClient.vbp
FormMain.frm
VBTestClient.vbw
VBWeatherStation
VBWeatherStation.vbw
VBWeatherStationForm.frm
VBWeatherStation.vbp
NETThreadDemoClient
NETThreadDemoClient.opt
NETThreadDemoClient.dsp
NETThreadDemoClient.dsw
HelloDotNet.tlb
ComInteropDemo
AirlineCSharpClient
AirlineInformation
AirlineInformation.opt
AirlineInfo.rgs
AirlineInformation.aps
AirlineInformation.tlb
AirlineInformation.def
AirlineInformationps.def
AirlineInformationps.mk
AirlineInformation.dsp
AirlineInformation.dsw
using System;
using MyFlyerMetadata;

// Inherit from the metadata type representing
// the unmanaged COM component
// Use the COM Component's implementation 
// of TakeOff  & Fly (Use base class implementation)
public class Bird : Flyer 
{

}/* end class Bird */

// Inherit from the metadata type representing
// the unmanaged COM component
// Override the COM object's method implementations in our
// derived managed-class.
// (Also call base class implementation when necessary)
public class Airplane : Flyer
{

       // Override the COM Component's Flyer::TakeOff implementation
       // with our own implementation
       public override String TakeOff() 
       {
	return "Airplane::TakeOff - This is .NET taking off";
       }


       // Override the COM Component's Flyer::Fly implementation
       // with our own implementation
       public override String Fly() 
       {
	// Can call the base class' implementation too if you
	// wish to.
	System.Console.WriteLine(base.Fly());

	return "Airplane::Fly - This is .NET in the skies";
        }

}/* end class Airplane */

// Contains an instance of the metadata type representing
// the unmanaged COM Component
public class HangGlider
{
	private Flyer flyer = new Flyer();
	
	// Forward the call to the contained class' implementation
	public String TakeOff() 
	{
		return flyer.TakeOff();
	}

	// Forward the call to the contained class' implementation
	public String Fly() 
	{
		// Do what you need to do before or after fowarding the 
		// call to flyer
		System.Console.WriteLine("In HangGlider::Fly - Before delegating to flyer.Fly");
		return flyer.Fly();
	}

}/* end class HangGlider */



public class FlightController
{
	public static void Main(String[] args)
	{
		Bird falcon = new Bird();
		System.Console.WriteLine("BIRD: CLEARED TO TAKE OFF");
		System.Console.WriteLine(falcon.TakeOff());
		System.Console.WriteLine(falcon.Fly());

		Airplane skyline = new Airplane();
		System.Console.WriteLine("AIRPLANE: CLEARED TO TAKE OFF");
		System.Console.WriteLine(skyline.TakeOff());
		System.Console.WriteLine(skyline.Fly());
		

		HangGlider glider = new HangGlider();
		System.Console.WriteLine("HANGGLIDER: CLEARED TO TAKEOFF");
		System.Console.WriteLine(glider.TakeOff());
		System.Console.WriteLine(glider.Fly());

	}/* end Main */

}/* end FlightController */

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

Share

About the Author

Aravind C
India India
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160919.1 | Last Updated 25 Jul 2001
Article Copyright 2001 by Aravind C
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid