AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

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

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Interop\TestClient_2\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




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


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.