Solved

Passing Types to ActiveX DLLs

Posted on 2000-04-04
17
143 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now