VB.NET, COM and VBScript

tymbow

Member
Joined
Dec 14, 2003
Messages
13
I want to use some of my .NET components with VBScript. I have managed to get COM Interop working without any trouble and have some test methods working with VBScript returning simple strings and arrays.

The problem I am having is with some of the more exotic object types. In my example code I want to return the XmlAttributeCollection type to VBScript, but no luck. VBScript keeps complaining it is not an object. If I use OLEView to look at the type info for my IConfig interface it tells me the return type is IUNKNOWN. From the little reading I did I gather this is bad, so I tried returning the object as type OBJECT but still no luck.

It is probably just my ignorance of the intricacies of COM but it it possible to return any object type I want to use with VBScript, and if so, how do you do it?

Note: I obviously left the workings of the code out to make things easier to read.

Code:
Imports System
Imports System.Xml
Imports System.Runtime.InteropServices

Namespace ScriptLib.Utility

    Public Interface IConfig
        Function GetConfigValue(ByVal configFile As String, ByVal xPath As String, ByVal keyname As String) As String
        Function GetconfigValues(ByVal configFile As String, ByVal xPath As String, ByVal keyname As String) As ArrayList
        Function GetAttributes(ByVal configFile As String, ByVal xPath As String) As XmlAttributeCollection
    End Interface

    <ComClass(Config.ClassId, Config.InterfaceId, Config.EventsId)> _
    Public Class Config

        Implements IConfig

         Define the GUIDs for the COM interfaces

        Public Const ClassId As String = "C200DEC2-5481-48d1-88ED-FB9000ED85C2"
        Public Const InterfaceId As String = "E77FA596-53CC-4f72-A769-F285A7E6659A"
        Public Const EventsId As String = "0FD78F07-D4C3-4bbf-AAAA-989FBBA3956A"



        Public Function GetConfigValue(ByVal configFile As String, ByVal xPath As String, ByVal keyname As String) As String Implements IConfig.GetConfigValue

             Code goes here

        End Function

        Public Function GetConfigValues(ByVal configFile As String, ByVal xPath As String, ByVal keyname As String) As ArrayList Implements IConfig.GetconfigValues

             Code goes here
            
        End Function


        Public Function GetAttributes(ByVal configFile As String, ByVal xPath As String) As XmlAttributeCollection Implements IConfig.GetAttributes

             Code goes here

        End Function

    End Class

End Namespace
 
Back
Top