Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Passing Types to ActiveX DLLs

I have a type:

Type sgl3DCoord
  x as single
  y as single
  z as single
End Type

and I want to pass it into a sub in a class module in a DLL.

I have tried:
Public Sub FillCoords(sgl3Dcoords() as object)
with no joy
0
MitchBroadhead
Asked:
MitchBroadhead
  • 12
  • 5
1 Solution
 
caraf_gCommented:
Well... since you're developing ActiveX components, why not create a class instead of a type?
0
 
caraf_gCommented:
Anyway, As Object will not work. As Object is only used for Object type variables. A TYPE is not an object.

0
 
MitchBroadheadAuthor Commented:
I am trying to pass a list of points to the Standard.exe GUI.  I have so many points that I can't create them all as classes, they have to be lists.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
caraf_gCommented:
Well, if you MUST.... (But, still, I recommend you use classes!)

Here's an example:

This is code in your ActiveX .dll

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
Private Type AHA
    A As Long
    B As Long
    C As Long
End Type
Public Sub woohoo(ByVal blokjes As Long)

Dim woohoo As AHA

CopyMemory VarPtr(woohoo), blokjes, 12

MsgBox woohoo.A
MsgBox woohoo.B
MsgBox woohoo.C

End Sub



0
 
caraf_gCommented:
And here is code in your calling application:

Option Explicit
Private Type AHA
    A As Long
    B As Long
    C As Long
End Type

Private Sub Command1_Click()

Dim woohoo As AHA
woohoo.A = 1
woohoo.B = 2
woohoo.C = 3

Dim objX As Class1
Set objX = New Class1
objX.woohoo VarPtr(woohoo)


End Sub

0
 
caraf_gCommented:
CopyMemory VarPtr(woohoo), blokjes, 12

the value "12" is the size of your Type in Bytes. You'll have to calculate this yourself for your situation. In my example I'm using a type with 3 Longs, which are 4 bytes each...
0
 
caraf_gCommented:
Don't use this on types that have variable elements, such as strings. Disaster will befall you if you do <g>
0
 
MitchBroadheadAuthor Commented:
Cheers Caraf g (:->)
Will it work with an array of type AHA?
0
 
caraf_gCommented:
Yes.... I'm going to try that out now to see if there are any hidden snags... hang on...
0
 
MitchBroadheadAuthor Commented:
Also, I need to pass in an empty array, and return a full one!!
0
 
caraf_gCommented:
Hm... dramatically changing the goalposts..

Will you know beforehand

a) How many you're going to get back
OR
b) The maximum number you're going to get back?
0
 
caraf_gCommented:
a)

Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
Private Type AHA
    A As Long
    B As Long
    C As Long
End Type
Public Sub woohoo(ByVal blokjes As Long, ByVal lngLBound As Long, ByVal lngUBound As Long)

Dim woohoo() As AHA

ReDim woohoo(lngLBound To lngUBound)
CopyMemory VarPtr(woohoo(1)), blokjes, 12 * (lngUBound - lngLBound + 1)

MsgBox woohoo(1).A
MsgBox woohoo(1).B
MsgBox woohoo(1).C
woohoo(2).A = 500

End Sub
0
 
caraf_gCommented:
Option Explicit
Private Type AHA
    A As Long
    B As Long
    C As Long
End Type

Private Sub Command1_Click()

Dim woohoo() As AHA

ReDim woohoo(1 To 3)
woohoo(1).A = 1
woohoo(1).B = 2
woohoo(1).C = 3
woohoo(2).A = 4
woohoo(2).B = 5
woohoo(2).C = 6
woohoo(3).A = 7
woohoo(3).B = 8
woohoo(3).C = 9

Dim objX As Class1
Set objX = New Class1
objX.woohoo VarPtr(woohoo(1)), 1, 3

End Sub
0
 
caraf_gCommented:
b) is a minor variation on a); I think you'd be able to work it out.
0
 
MitchBroadheadAuthor Commented:
Adjusted points from 50 to 100
0
 
MitchBroadheadAuthor Commented:
Okay, I'm starting to understand :)
I wish there was an easier way to fill a list than that :(
Have some extra points!!!
0
 
caraf_gCommented:
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 12
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now