|
How Do I...Call COM Methods from .NET?This example demonstrates how to use COM object from a Visual Basic .NET 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 .NET or with C#, you can reference the assembly using compiler /r switch or you can add reference to the project directly from Visual Studio .NET development tool. Namespace TestClient Public Class Test Public Shared Sub Main() Dim explorer As ExplorerLib.InternetExplorer Dim webBrowser As ExplorerLib.IWebBrowserApp explorer = New ExplorerLib.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 ExplorerLib.dll, which then can be referenced from code.
|