Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call C# DLL function from VBScript

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?

like image 662
abatishchev Avatar asked Apr 20 '09 17:04

abatishchev


People also ask

How do you call C in C++?

Just declare the C function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code. extern "C" void f(int); // one way.


2 Answers

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")
like image 83
Darin Dimitrov Avatar answered Sep 27 '22 19:09

Darin Dimitrov


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.

like image 43
danish Avatar answered Sep 27 '22 18:09

danish