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 TestClient {
public class Test {
public static void Main(){
SHDocVw.InternetExplorer explorer;
SHDocVw.IWebBrowserApp webBrowser;
explorer = new SHDocVw.InternetExplorer();
webBrowser = (SHDocVw.IWebBrowserApp) explorer;
webBrowser.Visible = true;
webBrowser.GoHome();
...
}
}
}
C#
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
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\howto\samples\Interop\TestClient_1\]
Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.
|