Solved

Passing Types to ActiveX DLLs

Posted on 2000-04-04
17
150 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses
Course of the Month3 days, 15 hours left to enroll

630 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