I've recently been looking for a way to use an unregistered DLL in VBScript. This accepted answer says that it can be accomplished using GetObject provided that (mentioned in the comments by the person who gave the answer) the DLL exposes a COM interface. I've never coded in C# before but I wanted to try it since the answer was for that language. After some searching, I found the following code example on this site:
using System;
using System.Runtime.InteropServices;
namespace Tester
{
[Guid("D6F88E95-8A27-4ae6-B6DE-0542A0FC7039")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Numbers
{
[DispId(1)]
int GetDay();
[DispId(2)]
int GetMonth();
[DispId(3)]
int GetYear();
[DispId(4)]
int DayOfYear();
}
[Guid("13FE32AD-4BF8-495f-AB4D-6C61BD463EA4")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Tester.Numbers")]
public class Numbers : _Numbers
{
public Numbers() { }
public int GetDay()
{
return (DateTime.Today.Day);
}
public int GetMonth()
{
return (DateTime.Today.Month);
}
public int GetYear()
{
return (DateTime.Today.Year);
}
public int DayOfYear()
{
return (DateTime.Now.DayOfYear);
}
}
}
Using Visual Studio 2010 Professional, I created a new C# class library and named it Tester. I copied the above code into the default Class1.cs file and compiled it. Then, I made a .vbs file with the following code:
Option Explicit
Dim Obj
' This part gives the following error message:
' ActiveX component can't create object: 'GetObject'
Set Obj = GetObject("C:\MyFolderPath\Tester.dll", "Tester.Numbers")
MsgBox Obj.GetDay
However, the code threw an error and would not instantiate the object. I tried running the .vbs file on the 32 and 64 bit version of wscript.exe because I'm on windows 7 64 bit. But, the error was the same both times. So, is there something I need to change in the C# code and/or some other option(s) I need to change in Visual Studio, or is the person's claim in the linked answer simply incorrect?
EDIT 1
My question is not a duplicate of this one. I realize the request there is of a similar nature. However, my question has to do with burden of proof. Nilpo has stated that GetObject will allow VBScript to instantiate an object using an unregistered C# DLL so long as it exposes a COM interface and even defended his position in that same question. I did the best I could to utilize the method he described and was unsuccessful. So, if it is possible, I would like to see a simple working example. And, if not, I was hoping to see some kind of documentation showing why not.
Furthermore, I will gladly use another programming language if that is truly the only way to allow the functionality I'm seeking. As such, I've removed C# from my question title and taken out the C# tag.
EDIT 2
I fixed the syntax highlighting for the original C# code I posted. It broke after I removed the C# tag from the question in my first edit.