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.Runtime.CompilerServices;
using System.Reflection;
using System.Diagnostics;

// Outgoing Event Interface which the Sink implements. We'll
// use a dispinterface here so that it remains friendly to
// scripting clients 
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface ITornadoWatchEvents 
{
    void OnTornadoWarning(int nWindSpeed);

}/* end interface ITornadoWatchEvents */

// Explicit incoming interface containing the methods
// being exposed to COM aware clients
public interface IWeatherNotify {

    int WindSpeed { get; set; }

}/* end interface IWeatherNotify */

// Delegate representing the OnTornadoWarning method of the outgoing event interface
public delegate void TornadoWarningDelegate(int nWindSpeed);


[ 
  ComSourceInterfaces("ITornadoWatchEvents"),
  ClassInterface(ClassInterfaceType.None)
]
public class WeatherNotify : IWeatherNotify
{
	// Indicates Windspeed in Miles Per Hour 
	private int m_nWindSpeed = 20;

	// Define an event associated with the TornadoWarningDelegate 
	public event TornadoWarningDelegate OnTornadoWarning;
	
	// Constructor
	public WeatherNotify() {
	}

	public int WindSpeed
	{
	      get {

	         // Return the current Wind speed 
                       return m_nWindSpeed;
                    }
	
	      set {

	          // Set the WindSpeed to the new value
                        m_nWindSpeed = value;
			
	          // Check if the Wind Speed warrants an event notification 
                        if(value >= 300) {

 		  try  {

		       // Check if the delegate instance for the event exists
		       if(null != OnTornadoWarning) {
				
		             // Twister on the loose. Run for cover !!!. 
		             // Fire the event to all the unmanaged sink handlers 
		             // that have registered for this event.
		            OnTornadoWarning(m_nWindSpeed);
			
		            OnTornadoWarning.Target.GetType().InvokeMember( "OnTornadoWarning",  BindingFlags.InvokeMethod, 
								      null,  OnTornadoWarning.Target, 
								      new object [] {m_nWindSpeed} );


		          } /* end if */

                               }/* end try */
		   catch(Exception ex) {

		       Trace.WriteLine(ex.Message);
                               }/* end catch */
				
	            }/* end if */

	      }/* end set */

         }/* End WindSpeed Property Accessors */

}/* end class WeatherNotify */

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
Web01 | 2.8.140827.1 | Last Updated 25 Jul 2001
Article Copyright 2001 by Aravind C
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid