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...Call COM Methods from .NET?

This example demonstrates how to use COM object from a Visual Basic or C# application.

In order to use the types defined within a COM library from managed code, you must 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 the project directly from Visual Studio development tool.

		

Namespace Microsoft.Samples.Interop.TestClient
	Public Class Test 	
		Public Shared Sub Main()
			Dim explorer As SHDocVw.InternetExplorer
			Dim webBrowser As SHDocVw.IWebBrowserApp
				
			explorer = New SHDocVw.InternetExplorer
			webBrowser = explorer
			
			webBrowser.Visible = True
			webBrowser.GoHome
			...
		End Sub
	End Class
End Namespace
VB

The following example uses the Internet Explorer object methods to display an Internet Explorer window and to navigate to the home page. In order to do that, an assembly containing definitions of the Internet Explorer types is created from SHDocVw.dll and saved into Interop.SHDocVw.dll, which then can be referenced from code.

TestClient.exe
View Source



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