Results 1 to 5 of 5

Thread: VS 2008 pass vba udt to vb.net dll

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    VS 2008 pass vba udt to vb.net dll

    I can make a vb.net dll with a com interface and it works fine when using it from VBA (Excel). I need to pass a udt into this .net dll and I am not having luck. Ive tried passing it as an object and Ive tried defining a structure exactly like the VBA UDT and passing it that way and it still doesnt work. The error I get complaines about an unsupported interface.

    Does anyone have any suggestions. If anyone knows of a small example anywhere Id appreciate being pointed to it. Ive done quite a bit of searching and cannot find anything.

    I tested the dll without any udts (just passing a string) and it worked fine, so Im sure Ive got it all setup right except for the UDT passing part.

    I dont need help on the VBA side ... I just need to know how to set up my vb.net dll to accept UDTs.

    Thanks in advance for any help.
    Last edited by Muddy; Apr 7th, 2009 at 08:43 PM. Reason: clarity

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: VS 2008 pass vba udt to vb.net dll

    What does your UDT look like?

    Could you create a COM version of your UDT and write a function that converts it from the VBA to the COM, basically just copying each property and then pass the COM version to the COM object? It sounds like you tried something like this, but I think you are going to have to copy each property individually to the COM object.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: VS 2008 pass vba udt to vb.net dll

    Quote Originally Posted by Negative0 View Post
    What does your UDT look like?

    Could you create a COM version of your UDT and write a function that converts it from the VBA to the COM, basically just copying each property and then pass the COM version to the COM object? It sounds like you tried something like this, but I think you are going to have to copy each property individually to the COM object.
    Thanks for the reply.

    I did try something similar that didnt work. I made a com object with an exact copy of the UDT, the referenced that inside vb.net and:

    Public Sub Bark(ByVal c() As COMobject.myUDT)
    MsgBox(c(1).StringOne)
    End Sub

    but I still get that interface error when I invoke Bark from VBA.

    Passing each prop individually isnt feasible for what I am doing.

    Sure does seem like Ive seen this done before somewhere, but I sure cant find an example ...

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: VS 2008 pass vba udt to vb.net dll

    Can you show your VBA code that calls the Bark function?

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    Re: VS 2008 pass vba udt to vb.net dll

    Quote Originally Posted by Negative0 View Post
    Can you show your VBA code that calls the Bark function?
    Sure ... here is the actual code I am testing with. I changed some names for brevity

    VBA (With referenence set to TestControl.tlb)
    Code:
    Option Explicit
    Sub tryOutBark()
    Dim a As New TestControl.Stuff
    Dim PassThis(1) As COMobject.myUDT
    PassThis(1).StringOne = "HI"
    Call a.Bark(PassThis)
    
    End Sub
    VB.NET

    Code:
    <ComClass(Stuff.ClassId, Stuff.InterfaceId, Stuff.EventsId)> _
    Public Class Stuff
        Public Const ClassId As String = "7D6A4AFE-0980-4697-BD22-1318EB7B52C3"
        Public Const InterfaceId As String = "6779DEAF-889C-459a-B813-7730B43928E8"
        Public Const EventsId As String = "2277792B-BD73-4538-A052-22481EDBF78B"
    
        Public Sub New()
            MyBase.New()
        End Sub
    
        Public Sub Bark(ByVal c() As COMobject.myUDT)
    
            MsgBox(c(1).StringOne)
        End Sub
    
    End Class
    When I try to execute the VBA code (inside Excel) I get the following compile error:

    Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic
    Many thanks for having a look at this and replying.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width