0

I have a dll containing VB6 classes (.cls files).

I have a VB script that uses these classes.

I have a C#.Net program that runs the script using Microsoft Script Control library (Ref: http://osherove.com/blog/2004/2/17/make-your-net-application-support-scripting-a-practical-appr.html)

Here's my code:

script = new MSScriptControl.ScriptControl();
script.Language = "VBScript";
script.AddObject("MyClass", account, true);
script.AddCode(GetScriptCode());
script.ExecuteStatement("RunThisMethod");

MyClass is the C# equivalent of the VB6 class with [ComVisible(true)]

[ComVisible(true)]
public class MyClass
{ ... }

I would like to know if instead of creating my own C# classes that are visible to COM, would it be possible for my code to use the VB6 classes from the dll and pass it to the script and if yes, how?

Update: I have registered all the needed COM components and now I can reference the COM dll. However, when I try to instantiate an object of the class in COM dll, I get the error 80040154 Class not registered at run-time

Rashmi Pandit
  • 23,230
  • 17
  • 71
  • 111
  • Not sure what you mean. Scripts already have access to both VB6 classes and ScriptingControl. Not sure why you would use three basics. –  Mar 15 '16 at 10:12
  • MyClass is a C# class not VB6. I have to define it as I don't know how to instantiate a VB6 class in .net and pass it. – Rashmi Pandit Mar 15 '16 at 11:36
  • Possible duplicate of [C# unit test with mocking for VBScript](http://stackoverflow.com/questions/35981405/c-sharp-unit-test-with-mocking-for-vbscript) – user692942 Mar 15 '16 at 12:02
  • Please don't duplicate post you already asked this yesterday and I asked you to post some of the code I didn't mean create a new question, just [update your existing one](http://stackoverflow.com/posts/35981405/edit). It's not like you are new to the site you should know better. – user692942 Mar 15 '16 at 12:03
  • Can't you just [add a reference to the VB6 DLL](http://stackoverflow.com/a/4561990/15639) in the C#, then create an instance of the VB6 object from C#, and pass it in to the VBScript? You do have a lot of layers here... – MarkJ Mar 15 '16 at 17:22
  • MarkJ, no I can't directly add the reference. It says please make sure that it is a valid assembly or COM component – Rashmi Pandit Mar 15 '16 at 22:21

0 Answers0