Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Understanding Classic COM Interoperability With .NET Applications

, 24 Jul 2001
Discusses how existing COM components can be used from managed code.
cominteropwithdotnetdemo.zip
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.zip
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
cominterop_demo.zip
ComInteropDemo
AirlineCSharpClient
AirlineInformation
AirlineInformation.opt
AirlineInfo.rgs
AirlineInformation.aps
AirlineInformation.tlb
AirlineInformation.def
AirlineInformationps.def
AirlineInformationps.mk
AirlineInformation.dsp
AirlineInformation.dsw
using System;
using System.Runtime.InteropServices;
using System.Reflection;
using AIRLINEINFORMATIONLib;


public class CAirlineClient
{

	public static void Main()
	{

		///////////////////////////////////////////////
		/// EARLY BINDING EXAMPLE
		///////////////////////////////////////////////

		String strAirline = "Air Scooby IC 5678";
		String strFoodJunkieAirline = "Air Jughead TX 1234";
		try
	   	{
			AirlineInfo objAirlineInfo;
			
			// Create a new AirlineInfo Object
			objAirlineInfo = new AirlineInfo();	

			// Display the output after calling the GetAirileTiming method
			System.Console.WriteLine("Details for Airline {0} --> {1}",
				strAirline,objAirlineInfo.GetAirlineTiming(strAirline)); 

			// System.Console.WriteLine("Details for Airline {0} --> {1}",
			// strFoodJunkieAirline,objAirlineInfo.GetAirlineTiming(strFoodJunkieAirline)); 

	        }//try 
		catch(COMException e)
		{
			System.Console.WriteLine("Oops- We encountered an error for Airline {0}. The Error message is : {1}. The  Error code is {2}",
				strFoodJunkieAirline ,e.Message,e.ErrorCode);			  	

		}// catch 

		///////////////////////////////////////////////
		/// QUERY INTERFACE/ RT type Checking
		///////////////////////////////////////////////

	
		try	
		{
			AirlineInfo objAirlineInfo;
			IAirportFacilitiesInfo objFacilitiesInfo;
			
			// Create a new AirlineInfo object	
			objAirlineInfo = new AirlineInfo();
		
			// Invoke the GetAirlineTiming method	
			String strDetails = objAirlineInfo.GetAirlineTiming(strAirline);	

			// QI for the IAirportFacilitiesInfo interface		
			objFacilitiesInfo = (IAirportFacilitiesInfo)objAirlineInfo;
			
			//Invoke a method on the IAirportFacilitiesInfo interface
			System.Console.WriteLine("{0}",objFacilitiesInfo.GetInternetCafeLocations());

        	} //try
		catch(InvalidCastException eCast)
		{	
			System.Console.WriteLine("We got an InvalidCast Exception - Message is {0}",eCast.Message);   

		}//catch

		///////////////////////////////////////////////
		/// LATE BINDING
		///////////////////////////////////////////////


		try
		{

			object objAirlineLateBound;
			Type objTypeAirline;
		      	object[] arrayInputParams= { "Air Scooby IC 5678" };
			objTypeAirline = Type.GetTypeFromProgID
                               ("AirlineInformation.AirlineInfo");
			objAirlineLateBound = Activator.CreateInstance(objTypeAirline);
			String str = (String)objTypeAirline.InvokeMember("GetAirlineTiming",
									BindingFlags.Default |	
					                                BindingFlags.InvokeMethod,
					                                null,
									objAirlineLateBound,
									arrayInputParams);

			System.Console.WriteLine("{0}",str);

			String strTime = (String)objTypeAirline.InvokeMember("LocalTimeAtOrlando", 
								BindingFlags.Default | 										BindingFlags.GetProperty, 
								null, 
								objAirlineLateBound,
								new object [] {});


		      Console.WriteLine ("Hi there !. The Local Time at Orlando,Florida is: {0}", strTime);
        

		}//try late binding
		catch(COMException e)
		{
	
			System.Console.WriteLine("Oops- We encountered an error for Airline {0}. The Error message is : 					{1}. The Error code is {2}",strFoodJunkieAirline ,e.Message,e.ErrorCode);			  	

	       }//catch


	}// Main

}

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

| Advertise | Privacy | Mobile
Web03 | 2.8.141029.1 | Last Updated 25 Jul 2001
Article Copyright 2001 by Aravind C
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid