I am trying to call a method I have written in C# from VBScript.
I have followed just about all of the instructions I can find on the web and am still having problems.
Specifically I am getting
Error: ActiveX component can’t create object
Code: 800A01AD
So far I have done the following:
- Set
ComVisible(true) - Registered using
regasm /codebase - Strong named my assembly
- Confirmed it is in the registry and points to the correct location
- Made the class public
- Have no static methods
- Made the method I want to call public
- Have a parameterless constructor
- Explicitly defined a GUID
My VBScript looks like this:
set oObject = CreateObject("TTTTTT.FFFFF.CCCCCCCCC")
My C# code looks like this:
using System;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace XXXXX.YYYYY
{
[ComVisible(true)]
[Guid("3EB62C37-79BC-44f7-AFBD-7B8113D1FD4F")]
[ProgId("TTTTTT.FFFFF.CCCCCCCCC")]
public class CCCCCCCCC
{
public void MyFunc()
{
//
}
}
}
Can anyone help?
Here’s a simple project with only a few steps, to get you started.
C# code:
VBScript client code:
To build:
Then just run the vbscript (through cscript.exe).
Once you get the basic thing working, you can tweak it, add GAC, make the typelib explicit, add an explicit ProgId, and so on.
ps: FYI, this example shows what happens with overloaded .NET methods on a class registered for interop. There’s an implicit _2 (_3, _4, etc) appended to the method name.