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.
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.
Re: VS 2008 pass vba udt to vb.net dll
Quote:
Originally Posted by
Negative0
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 ...
Re: VS 2008 pass vba udt to vb.net dll
Can you show your VBA code that calls the Bark function?
Re: VS 2008 pass vba udt to vb.net dll
Quote:
Originally Posted by
Negative0
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:
Quote:
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.