C # code could not be called from vbscript - ActiveX error

I am trying to call a method that I wrote in C # from VBScript.

I have followed almost all the instructions that I can find on the Internet and am still having problems.

In particular, I get

Error: ActiveX component cannot create object

Code: 800A01AD

So far I have done the following:

  • Install ComVisible(true)
  • Registered with regasm /codebase
  • Strongly called my assembly
  • It is confirmed that it is in the registry and indicates the correct location.
  • Created a class public
  • No static methods
  • Made a method that I want to call public
  • Has a constructor without parameters
  • Explicitly defined GUID

My VBScript looks like this:

set oObject = CreateObject("TTTTTT.FFFFF.CCCCCCCCC")

My C # code is as follows:

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?

+5
5

, .

#:

using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly:System.CLSCompliant(true)]
[assembly: ComVisible(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("7d9c5cd3-73d4-4ab1-ba98-32515256c0b0")]

namespace Cheeso.ComTests
{
    [Guid("7d9c5cd3-73d4-4ab1-ba98-32515256c0b1")]
    public class TestReply
    {
        public string salutation;
        public string name;
        public string time;
    }

    [Guid("7d9c5cd3-73d4-4ab1-ba98-32515256c0b2")]
    public class TestObj
    {
        // ctor
        public TestObj () {}

        public TestReply SayHello(string addressee)
        {
            return SayHello(addressee, "hello");
        }

        public TestReply SayHello(string addressee, string greeting)
        {
            string x = String.Format("{0}, {1}!", greeting, addressee);
            Console.WriteLine("{0}", x);

            TestReply r = new TestReply
            {
                salutation = greeting,
                name = addressee,
                time = System.DateTime.Now.ToString("u")
            };
            return r;
        }
    }
}

VBScript:

Function Main()
    Dim obj
    Dim reply
    set obj = CreateObject("Cheeso.ComTests.TestObj")
    Set reply = obj.SayHello("Evgeny")
    WScript.Echo "Reply at: " & reply.time
    Set reply = obj.SayHello_2("Evgeny", "wassup")
    WScript.Echo "Reply at: " & reply.time
End Function

Main

:

(produce your .snk file, once)
csc.exe /t:library /debug+ /keyfile:Foo.snk /out:TestObj.dll TestObj.cs
regasm /codebase TestObj.exe

vbscript ( cscript.exe).

, , GAC, typelib , ProgId ..

ps: FYI, , .NET , . _2 (_3, _4 ..) .

+2

: COM Interop Exposed

(3) :

  • .NET , COM.
  • GUID "Guid".
  • .
  • GUID "Guid".
  • "ClassInterface(ClassInterfaceType.None)" regasm/tlbexp .
  • AssemblyVersion.
  • AssemblyKeyFile.
  • GAC,
  • COM REGASM "/tlb" COM .

, GAC ClassInterfaceType.None , , . !

+4

- , , . , , , script . - ProcMon SysInternals.

, ProcMon:

22  12:04:41.1795038 PM WScript.exe 55280   RegOpenKey  HKCR\TTTTTT.FFFFF.CCCCCCCCC SUCCESS Desired Access: Read
26  12:04:41.1795682 PM WScript.exe 55280   RegOpenKey  HKCR\TTTTTT.FFFFF.CCCCCCCCC\CLSID   SUCCESS Desired Access: Read
29  12:04:41.1796996 PM WScript.exe 55280   RegQueryValue   HKCR\TTTTTT.FFFFF.CCCCCCCCC\CLSID\(Default) SUCCESS Type: REG_SZ, Length: 78, Data: {3EB62C37-79BC-44F7-AFBD-7B8113D1FD4F}
34  12:04:41.1797653 PM WScript.exe 55280   RegOpenKey  HKCR\CLSID\{3EB62C37-79BC-44F7-AFBD-7B8113D1FD4F}   SUCCESS Desired Access: Read
62  12:04:41.1802539 PM WScript.exe 55280   RegOpenKey  HKCR\CLSID\{3EB62C37-79BC-44F7-AFBD-7B8113D1FD4F}\InprocServer32    SUCCESS Desired Access: Read
71  12:04:41.1804181 PM WScript.exe 55280   RegQueryValue   HKCR\CLSID\{3EB62C37-79BC-44F7-AFBD-7B8113D1FD4F}\InprocServer32\(Default)  SUCCESS Type: REG_SZ, Length: 24, Data: mscoree.dll
824 12:04:41.2425662 PM WScript.exe 55280   RegQueryValue   HKCR\CLSID\{3EB62C37-79BC-44F7-AFBD-7B8113D1FD4F}\InprocServer32\1.0.0.0\CodeBase   SUCCESS Type: REG_SZ, Length: 124, Data: file:///c:/projects/ClassLibrary2/obj/Debug/ClassLibrary2.DLL
... Lots of .NET keys...
1239    12:04:41.2970169 PM WScript.exe 55280   CreateFile  C:\projects\ClassLibrary2\obj\Debug\ClassLibrary2.dll   SUCCESS Desired Access: Read Attributes, Disposition: Open, Options: Open Reparse Point, Attributes: n/a, ShareMode: Read, Write, Delete, AllocationSize: n/a, OpenResult: Opened
+4

Cheeso 64- , , CScript.exe :

%windir%\SysWOW64\cscript.exe test.vbs

: CreateObject VB Windows 7 x64

+1

, VS. ,

csc.exe /t:library AClass.cs /keyfile:Foo.snk - produce your key file with VS!
regasm /codebase /tlb AClass.dll

VS , /warn:/noconfig .., , System.Core .., erros. csc .

0

All Articles