Page view counter

These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Sink Unmanaged Events from .NET?

This example demonstrates how to sink unmanaged events from .NET code.

In order to use the types defined within a COM library from managed code, you have to obtain an assembly containing definitions of the COM types. Refer to the How Do I...Build a .NET Client That Uses a COM Server? for specific details.

With Visual Basic or with C#, you can reference the assembly using compiler /r switch or you can add reference to your project directly from the Visual Studio development tool.

Once you have a reference, you can create new instances of the event handlers and add them to existing event handlers in unmanaged code. For specific syntax see examples below.


		
Public Shared Sub Main()
	Dim explorer As SHDocVw.InternetExplorer
	Dim webBrowser As IWebBrowserApp
		
	explorer = New SHDocVw.InternetExplorer
	webBrowser = explorer
	
	'Title Change event
	AddHandler explorer.TitleChange, AddressOf OnTitleChange		
	
	
	
	webBrowser.Visible = True
	webBrowser.GoHome
	...		
End Sub

Public Shared Sub OnTitleChange(txt As String)
	Console.WriteLine("Title changes to {0}", txt)
End Sub
VB

The following example uses the Internet Explorer object methods and events to open an Internet Explorer window, catch all TitleChange events and show them in console window. To do this, an assembly containing definitions of the Internet Explorer types and events is created from SHDocVw.dll and saved into ExplorerLib.dll, which then can be referenced from the code.

TestClient.exe
View Source



Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.