1

I've created Class library project with next code and settings:

using System.Runtime.InteropServices;

namespace MyDll
{
    [ComVisible(true)]
    public class TestClass
    {
        [ComVisible(true)]
        public string[] SomeFunc(string path)
        {
            return new[] {"1","7","9"};
        }
    }
}

Also checked

'Make Assembly COM-Visible' in Properties/Application/Assembly information

and

'Register for COM interop' in Properties/Build

In my VBscript I am getting exception

"0x800a01ad - Microsoft VBScript runtime error: ActiveX component can't create object: 'MyDll.TestClass'"

when trying to create object from dll:

Dim result
Dim myObj
Set myObj = CreateObject("MyDll.TestClass")
Set result= myObj.SomeFunc("a")
user692942
  • 14,779
  • 6
  • 66
  • 157
Ted
  • 1,193
  • 3
  • 15
  • 32
  • 1
    Have you [registered the actually DLL using `regsvr32.exe`](http://stackoverflow.com/a/35985827/692942) *(the advice applies to both server-side and client-side VBScript)*? – user692942 Apr 26 '16 at 10:53
  • 'Register for COM interop' in Properties/Build means registration dll by regasm.exe – Ted Apr 26 '16 at 11:01
  • for COM we need to use regasm.exe. http://www.codeproject.com/Articles/79314/How-to-call-a-NET-DLL-from-a-VBScript – Ted Apr 26 '16 at 11:05
  • But which registry is it being registered in? If `regasm.exe` is doing the job of `regsvr32.exe` or even calling it itself, which one is getting called? *(see that link for breakdown of 32-bit and 64-bit registry locations and how using the wrong `regsvr32.exe` can affect where it ends up)*. – user692942 Apr 26 '16 at 11:06

1 Answers1

1

You might be using regasm.exe to add the Class into the registry but where in the registry?

Problem is we have the complication of dealing with both 32-bit and 64-bit architectures, so couple of things spring to mind.

How are you running the script

Dim result
Dim myObj
Set myObj = CreateObject("MyDll.TestClass")
Set result= myObj.SomeFunc("a")

If you are using the default wscript.exe Windows Scripting Host to run the script then it will default to OS architecture which in most modern installations will be 64-bit OS.

If regasm.exe isn't registering the Class with the 64-bit registry then CreateObject will never find the prog id MyDll.TestClass.

Check through this article and see if you can see the Class in the registry, it details the various locations to check for both 32-bit and 64-bit.


Useful Links

Community
  • 1
  • 1
user692942
  • 14,779
  • 6
  • 66
  • 157