


The implementation in this example just shows a Message Box, so we know when the Dispose method is getting called. Just change the implementation of the Dispose method to clean up any resources used by the COM component. In our example, the Dispose method we added could be used for this purpose. You can use the onunload event to detect when the page is unloaded, then dispose of your COM component. In Internet Explorer 8, the COM component is not destroyed until the web browser is fully closed - closing of the tab that contained the COM component does not dispose of the object! If the user continuously hits the refresh button, new instances of the COM component will be created, but the old instances won't be released until the web browser is closed. Var returnCode = m圜omComponent.MyFirstComCommand( " Hello World!") Disposing of the COM Component To use the COM component in a web page, embed an tag in the head of the page } Creating an Instance of the COM Component Show( " M圜omComponent is now disposed") Public int MyFirstComCommand( string arg) Public event MyFirstEventHandler MyFirstEvent Public delegate void MyFirstEventHandler( string args) Exclude Class1.cs from the project.Īdd a class named M圜omObject.cs to the project, change the access modifier to public, and import the namespace: If you are using Vista, you will need to run Visual Studio as an administrator to build your project after changing this setting. Creating the C# COM LibraryĬreate a new C# Class Library project called M圜omComponent, and enable the setting “Register for COM interop” in the build settings for the project. Complete source code for the COM object, as well as a simple web page that demonstrates how to use the COM object is provided, including how to make calls into the COM Object, and how to handle. NET 2005) that can be used in JavaScript inside a web browser (only tested on IE 8 RC on Windows Vista).

This article describes how to create a C# COM Object (using Visual Studio. In this article, I will put together all the pieces to show how to implement a complete solution, to use C# COM objects inside JavaScript. NET events through COM, and use the COM object in JavaScript to my satisfaction.

A Google search turned up many helpful articles, but nothing that showed how to create a COM component in C#, surface. NET COM component and use the ActiveXObject in JavaScript to interact with the COM object. After searching the web (including CodeProject), I found that a possible solution would be to create a.
