Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. VB6 to VB.Net COM Interface Help

VB6 to VB.Net COM Interface Help

Scheduled Pinned Locked Moved Visual Basic
helpcsharpcomwindows-admin
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sashaw2
    wrote on last edited by
    #1

    Why do i get the error - "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic", when I try to pass a String array from vb6 to a class:Property string array in vb.net? This is the vb6 code:

    Option Explicit

    Private Sub btnTest_Click()
    Dim strTest(4) As String
    strTest(1) = "abc"
    strTest(2) = "def"
    strTest(3) = "ghi"
    strTest(4) = "jkl"

    On Error GoTo err1
        
    Dim clsTest As ComTest.clsValues
    Set clsTest = New ComTest.clsValues
    
    clsTest.SingleString = "this is my string"
    clsTest.stringArray = strTest   ' <<
    

    This is the vb.net class

    Imports System.Runtime.InteropServices

    _
    Public Class clsValues

    #Region "COM GUIDs"
    ' These GUIDs provide the COM identity for this class
    ' and its COM interfaces. If you change them, existing
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "095dc64d-141f-46f9-9af2-1c5e633b459b"
    Public Const InterfaceId As String = "86ec1f14-1ef4-446d-9172-b92cf260cd16"
    Public Const EventsId As String = "1605e412-8b11-4ee0-a34c-9ec04464737f"
    #End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub
    
    Private mSingleString As String
    Public Property SingleString() As String
        Get
            Return mSingleString
        End Get
        Set(ByVal value As String)
            mSingleString = value
        End Set
    End Property
    
    Private mStringArray() As String
    Public Property StringArray() As  String()
        Get
            Return mStringArray
        End Get
        Set(
    
    Richard DeemingR 2 Replies Last reply
    0
    • S sashaw2

      Why do i get the error - "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic", when I try to pass a String array from vb6 to a class:Property string array in vb.net? This is the vb6 code:

      Option Explicit

      Private Sub btnTest_Click()
      Dim strTest(4) As String
      strTest(1) = "abc"
      strTest(2) = "def"
      strTest(3) = "ghi"
      strTest(4) = "jkl"

      On Error GoTo err1
          
      Dim clsTest As ComTest.clsValues
      Set clsTest = New ComTest.clsValues
      
      clsTest.SingleString = "this is my string"
      clsTest.stringArray = strTest   ' <<
      

      This is the vb.net class

      Imports System.Runtime.InteropServices

      _
      Public Class clsValues

      #Region "COM GUIDs"
      ' These GUIDs provide the COM identity for this class
      ' and its COM interfaces. If you change them, existing
      ' clients will no longer be able to access the class.
      Public Const ClassId As String = "095dc64d-141f-46f9-9af2-1c5e633b459b"
      Public Const InterfaceId As String = "86ec1f14-1ef4-446d-9172-b92cf260cd16"
      Public Const EventsId As String = "1605e412-8b11-4ee0-a34c-9ec04464737f"
      #End Region

      ' A creatable COM class must have a Public Sub New() 
      ' with no parameters, otherwise, the class will not be 
      ' registered in the COM registry and cannot be created 
      ' via CreateObject.
      Public Sub New()
          MyBase.New()
      End Sub
      
      Private mSingleString As String
      Public Property SingleString() As String
          Get
              Return mSingleString
          End Get
          Set(ByVal value As String)
              mSingleString = value
          End Set
      End Property
      
      Private mStringArray() As String
      Public Property StringArray() As  String()
          Get
              Return mStringArray
          End Get
          Set(
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      You don't seem to be setting the StringArray property anywhere. You also have a line which doesn't look like it should compile:

      clsTest strTest

      Is this a typo in your question?


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      S 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        You don't seem to be setting the StringArray property anywhere. You also have a line which doesn't look like it should compile:

        clsTest strTest

        Is this a typo in your question?


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        S Offline
        S Offline
        sashaw2
        wrote on last edited by
        #3

        Thank you for the reply It is a typo but this is where the error occurs, see error message at top of message after correction.

        1 Reply Last reply
        0
        • S sashaw2

          Why do i get the error - "Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic", when I try to pass a String array from vb6 to a class:Property string array in vb.net? This is the vb6 code:

          Option Explicit

          Private Sub btnTest_Click()
          Dim strTest(4) As String
          strTest(1) = "abc"
          strTest(2) = "def"
          strTest(3) = "ghi"
          strTest(4) = "jkl"

          On Error GoTo err1
              
          Dim clsTest As ComTest.clsValues
          Set clsTest = New ComTest.clsValues
          
          clsTest.SingleString = "this is my string"
          clsTest.stringArray = strTest   ' <<
          

          This is the vb.net class

          Imports System.Runtime.InteropServices

          _
          Public Class clsValues

          #Region "COM GUIDs"
          ' These GUIDs provide the COM identity for this class
          ' and its COM interfaces. If you change them, existing
          ' clients will no longer be able to access the class.
          Public Const ClassId As String = "095dc64d-141f-46f9-9af2-1c5e633b459b"
          Public Const InterfaceId As String = "86ec1f14-1ef4-446d-9172-b92cf260cd16"
          Public Const EventsId As String = "1605e412-8b11-4ee0-a34c-9ec04464737f"
          #End Region

          ' A creatable COM class must have a Public Sub New() 
          ' with no parameters, otherwise, the class will not be 
          ' registered in the COM registry and cannot be created 
          ' via CreateObject.
          Public Sub New()
              MyBase.New()
          End Sub
          
          Private mSingleString As String
          Public Property SingleString() As String
              Get
                  Return mSingleString
              End Get
              Set(ByVal value As String)
                  mSingleString = value
              End Set
          End Property
          
          Private mStringArray() As String
          Public Property StringArray() As  String()
              Get
                  Return mStringArray
              End Get
              Set(
          
          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          I suspect the problem is that the array needs to be passed ByRef, which isn't supported in property setters. Try replacing the property setter with a method:

          Public Property StringArray() As String()
          Get
          Return mStringArray
          End Get
          End Property

          Public Sub SetStringArray( ByRef value As String())
          mStringArray = value
          End Sub


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          S 1 Reply Last reply
          0
          • Richard DeemingR Richard Deeming

            I suspect the problem is that the array needs to be passed ByRef, which isn't supported in property setters. Try replacing the property setter with a method:

            Public Property StringArray() As String()
            Get
            Return mStringArray
            End Get
            End Property

            Public Sub SetStringArray( ByRef value As String())
            mStringArray = value
            End Sub


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            S Offline
            S Offline
            sashaw2
            wrote on last edited by
            #5

            I read setting the parameter ByRef and not ByVal would work but wasn't sure how to set it up. A little tweaking and the vb.net code looks like this:

            _
            Public Class clsValues

            #Region "COM GUIDs"
            ' These GUIDs provide the COM identity for this class
            ' and its COM interfaces. If you change them, existing
            ' clients will no longer be able to access the class.
            Public Const ClassId As String = "095dc64d-141f-46f9-9af2-1c5e633b459b"
            Public Const InterfaceId As String = "86ec1f14-1ef4-446d-9172-b92cf260cd16"
            Public Const EventsId As String = "1605e412-8b11-4ee0-a34c-9ec04464737f"
            #End Region

            ' A creatable COM class must have a Public Sub New() 
            ' with no parameters, otherwise, the class will not be 
            ' registered in the COM registry and cannot be created 
            ' via CreateObject.
            Public Sub New()
                MyBase.New()
            End Sub
            
            Private mSingleString As String
            Public Property SingleString() As String
                Get
                    Return mSingleString
                End Get
                Set(ByVal value As String)
                    mSingleString = value
                End Set
            End Property
            
            Private mStringArray As String()
            Public Function StringArray() As String()
                Return mStringArray.ToArray
            End Function
            Public Function StringArray(i As Short) As String
                Return mStringArray(i)
            End Function
            Public Sub SetStringArray( ByRef value As String())
                mStringArray = value
            End Sub
            

            End Class

            The final vb6 code looks like this:

            Option Explicit

            Private Sub btnTest_Click()
            Dim x As Integer
            Dim strTest(4) As String
            strTest(1) = "abc"
            strTest(2) = "def"
            strTest(3) = "ghi"
            strTest(4) = "jkl"

            On Error GoTo err1
                
            Dim clsTest As comtest.clsValues
            Set clsTest = New comtest.clsValues
            
            clsTest.SingleString = "this is my string"
            clsTest.SetStringArray strTest
            
            MsgBox "Single string = " & clsTest.SingleString, vbInformation, "Test"
            
            For x = 1 To UBound(clsTest.StringArray) 'clsTest.UboundStringArray
                MsgBox "Multi string " & x & " = " & clsTest.StringArray\_2(x), vbInformation, "Test"
            Next x
            
            Exit Sub
            

            err1:
            MsgBox "Error: " & Err.Number & vbCrLf & Err.Descrip

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups