tags:

views:

38

answers:

2

Hi all, can anyone point me to an example that show how to pass and/or return a class from a .NET class exposed as COM. The COM consumer would be a VBScript. Also, it is possible to pass an object from VBScript to a .NET-COM exposed method? For example

[ComVisible(true)]
public class A
{
       public SomeClass MethodName(NameValueCollection param)
       {
           return new SomeClass();
       }
}

How do you call MethodName in VBScript (ASP)

Thanks!

+1  A: 

I don't think NameValueCollection is marked as ComVisible, so I suspect no.

Preet Sangha
A: 

In VBScript, to create and use the object...


set obj= CreateObject("your.fully.qualified.com.classname")
obj.Do_Some_Method(some_obj_param, another_obj_param)
obj.Some_Property = anything

The only factors when passing values of any kind back and forth are a) how does your COM class translate them back and forth; and b) how does your consuming/client language translate them back and forth. Objects are Objects. But fundamentally, the COM class you create, call, or assign by must have its interface properly set up and registered. And (I think) whatever object you create using CreateObject() must implement one of several properties exposing it to COM to be able to use any of its methods or access its properties. Namely the ComVisible(true) attribute.

You'll find most .Net default classes are not fully callable using COM even if marked otherwise in documentation (likely either because your consumer/client language can't handle it or it really isn't COM callable), and therefore you have to make your own custom COM Callable Wrapper.

bob-the-destroyer