Solved

Passing Types to ActiveX DLLs

Posted on 2000-04-04
17
146 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

828 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