Solved

Passing Types to ActiveX DLLs

Posted on 2000-04-04
17
147 Views
Last Modified: 2010-05-02
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
Comment
Question by:MitchBroadhead
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 5
17 Comments
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683286
Well... since you're developing ActiveX components, why not create a class instead of a type?
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683288
Anyway, As Object will not work. As Object is only used for Object type variables. A TYPE is not an object.

0
 
LVL 1

Author Comment

by:MitchBroadhead
ID: 2683290
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
Industry Leaders: 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!

 
LVL 10

Expert Comment

by:caraf_g
ID: 2683299
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683301
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683306
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683308
Don't use this on types that have variable elements, such as strings. Disaster will befall you if you do <g>
0
 
LVL 1

Author Comment

by:MitchBroadhead
ID: 2683330
Cheers Caraf g (:->)
Will it work with an array of type AHA?
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683343
Yes.... I'm going to try that out now to see if there are any hidden snags... hang on...
0
 
LVL 1

Author Comment

by:MitchBroadhead
ID: 2683355
Also, I need to pass in an empty array, and return a full one!!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683578
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683586
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
 
LVL 10

Accepted Solution

by:
caraf_g earned 100 total points
ID: 2683589
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
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683592
b) is a minor variation on a); I think you'd be able to work it out.
0
 
LVL 1

Author Comment

by:MitchBroadhead
ID: 2683783
Adjusted points from 50 to 100
0
 
LVL 1

Author Comment

by:MitchBroadhead
ID: 2683784
Okay, I'm starting to understand :)
I wish there was an easier way to fill a list than that :(
Have some extra points!!!
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2683896
Thanks!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question