Re: Interface question

From: Adrian Forbes [ASP MVP] (sorry_at_noemail.zzz)
Date: 02/23/04


Date: Mon, 23 Feb 2004 23:48:19 -0000

You can't do this from VBScript.

A COM object has a number of interfaces. If I create a COM object called
MyProject.MyClass that has an interface called IMyInterface then your COM
class has;

IUnknown - this lets any client query the object for a reference count and
to see what interfaces it supports

IDispatch - this is a list of functions the object supports that allows
late-binding via querying for a function by name.

_MyClass - this contains all public methods on MyClass and is called the
default interface. It is implemented for you under the covers by VB.

IMyInterface - this contains all public methods on IMyInterface.

When VB is the client of a COM object it can see and use *all* of these
interfaces. However VBScript is limited to IUnknown (all COM objects have
this and all COM clients must understand it) and IDispatch.

So VBScript clients can only use late binding for COM and/or the default
interface. So why can it see your public methods that are in _MyClass?
Because it is up to whatever builds the COM object to decide what goes in
IDispatch and the VB compiler chooses to only put the public methods in your
default interface into IDispatch. It will not put the methods in
IMyInterface into IDispatch.

In a nut-shell that is why you can't access custom interfaces on your VB
objects from VBScript.

"Andy Ranoe" <andy.ranoe@ntlworld.com> wrote in message
news:f9q_b.2259$Vv.1861@newsfe2-gui.server.ntli.net...
> I have just started playing about with interface inheritance using the
> 'Implements' thing
>
> All works fine in the VB proper because you go ...
>
> Dim xObj as ILib.IClass
> .....
> .....
> Set xObj = CreateObject("Lib.Class")
>
> and this makes the connections between the interface definitions and their
> implementations
>
> How do I do this in VBScript ???
>
> When you Set xObj = CreateObject("Lib.Class")
>
> - the concrete class Lib.Class doesn't have the properties and methods
> - can't use the DIM statement to tie up with the interface
>
> ----So what do I have to do
>
>
> TIA
>
> Andy
>
>



Relevant Pages

  • Marshaler bug with VBScript arrays
    ... Interop marshaler won't pass VBScript arrays to my interface by reference. ... In the C++ code, I dereference it manually to get to the array, and I use ... MarshalAs(UnmanagedType.CustomMarshaler) attribute with a custom ...
    (microsoft.public.dotnet.framework.interop)
  • Re: COM interop
    ... What attributes did you set on your methods, remember vbscript can only call ... public interface IDotNetInterface ... public int someMethod() ... Dim var, ret ...
    (microsoft.public.dotnet.languages.csharp)
  • JScript and DLLs/Server Side Objects
    ... JScript and the object appears to present a broken interface to me...there ... I decided to rewrite one page in VBScript and see ... Is this an issue between JScript and VBScript, or is it possible that my 3rd ...
    (microsoft.public.inetserver.asp.general)
  • Cannot access C# collection item from scripting
    ... I'm trying to acces a C# collection from VBScript. ... I cannot see any relevant differences in the typelib between my interface ... public class Person: IPerson ... public class PersonCollection: IPersonCollection ...
    (microsoft.public.dotnet.framework.interop)
  • IDispatch* , COM Server(LOCAL_SERVER), event data and C#.NET
    ... I have one main inbound interface called ... If IDispatch is the answer, I already did the following, ... I did code following C++ wrapper class for the _ICallInfo impl. ... // object before calling the base class. ...
    (microsoft.public.dotnet.framework.interop)

Loading