views:

403

answers:

2

Hello everyone,

How to call COM object from classic ASP? I tried hard but cannot find a good tutorial. Any recommendations?

I am using C# in classic ASP.

thanks in advance, George

+4  A: 

To instantiate a COM object in classic ASP:

Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

COM objects are registered (in the registry) with a name known as the ProgId, which is ("ADODB.Recordset") in the above snippet.

Heres's a tutorial: Using COM Objects

Update, in response to posters comments: If you are creating a .NET assembly, then you will need to run regasm.exe on it to create the necessary information to allow COM clients to create .NET Framework classes.

The regasm.exe tool works by reading the declaration of your class, and in particular the class-level attributes GuidAttribute and ProgID as shown here:

using System.Runtime.InteropServices;

[GuidAttribute("581C28BD-E701-4AC1-BD75-0979BCEEC91E"),
ProgId("WordAddin1.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{

}
Mitch Wheat
Thanks Mitch, I am calling some customized 3rd party COM object, not .Net built in ones. Also I am beginner for this topic and I want to read some several-page long tutorials to bring me to the big picture. Any recommended readings?
George2
Strictly speaking .NET doesn't have any 'builtin' COM objects (but it does provide wrappers over some).
Mitch Wheat
Thanks Mitch, I am wrting COM object by using C#, and let classic ASP call it. The method about how I create COM object by using C# could be found here => http://www.codeproject.com/KB/COM/com_object_in_c_.aspx?display=Print in this method I think there is no progid, just a typelib? I need to generate an additional progid?
George2
Thanks Mitch, where in my .Net code to assign progID?
George2
+2  A: 

If you're using JavaScript:

var obj = new ActiveXObject("Some.Object")

For example, see this page:

This assumes that "Some.Object" has been registered as a COM object (for example, using "regsvr32 /register SomeObject.dll").

For further reading, O'Reilly had a decent book on this and you might consider reading this sample chapter:

or this tutorial:

ars
Sorry ars, I am using VBScirpt. I have browsed the tutorials, seems all of them are either dealing with Javascript or dealing with how to create COM object by classic ASP? What I am asking is how to invoke COM object from classic ASP. Any recommended readings?
George2
Try starting from here on the MSDN site: http://msdn.microsoft.com/en-us/library/ms524786.aspx and poke around the rest of the docs.
ars
Cool, question answered!
George2