11

I have my script on server, so I do not have UI interaction available and have to use DLL instead of console application.

How to call a function in C# DLL from VBScript?

How do I make my DLL to be COMVisible? Do I have to register it?

1

2 Answers 2

22

You need to mark your assembly as COM visible by setting the COMVisibleAttribute to true (either at assembly level or at class level if you want to expose only a single type).

Next you register it with:

regasm /codebase MyAssembly.dll

and finally call it from VBScript:

dim myObj
Set myObj = CreateObject("MyNamespace.MyObject")
Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to use Dim myObj As MyNamespace.MyObject in VBScript as you can in VBA so you don't need CreateObject? Is there an explicit reference you can make?
2

Yes you will need to set the ComVisible attribute to true and then register the assembly using regasm or regsvcs along with tlbexp. Then you can use Server.CreateObject and sail through.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.