Click to See Complete Forum and Search --> : How do you convert this C++ function to vb declaration?
misterkiasu
Nov 7th, 2000, 09:28 PM
Hi all,
Any idea on how to convert this c++ function header to vb declaration ?
UINT CmdDownLoadIULabel(myStructures theArray[500]);
I am more concerned on how I am to declare the Array part (theArray[500]).
Thanks
rfo
Nov 9th, 2000, 06:49 AM
It should be enough to pass the first entries addres.
Declare Function CmdDownLoadIULabel Lib "..." (ByVal myStructures as Any)as integer
ret = CmdDownLoadIULabel (myStructure(1))
you need to make sure the procedure knows how many entries are in the array.
Mad Compie
Nov 9th, 2000, 02:19 PM
Hmm, let's take a closer look.
UINT CmdDownLoadIULabel(myStructures theArray[500]);
UINT means that the return value is an unsigned integer. In VB you have to use a Long, since bit 15 can't be 1 in an Integer.
CmdDownLoadIULabel is the name of the function. No problem.
The parameter theArray[500] is an array with 500 elements [0..499] of a type called myStructures and has to be defined with the Type statement in VB.
I should redeclare this function in VB like:
Function CmdDownLoadIULabel (theArray() As myStructures) As Long
But VB gives me an error when using the user-defined type myStructures. By now, I don't know how to pass a user-defined type to a function.
I'll keep in touch...
Mad Compie
Nov 9th, 2000, 02:30 PM
Here we are again...
If you want to pass a user-defined type to a function, then this function has to be declared as Private, otherwise you get an error (like I did)!
So, here's the solution:
'In a form...
Option Explicit
Private Type myStructures
a As Integer
b As Byte
c() As Long
'...
End Type
Dim theArray(500) As myStructures
Private Sub Form_Load()
CmdDownLoadIULabel theArray
End Sub
Private Function CmdDownLoadIULabel (ByRef theArray() As myStructures) As Long
Debug.Print UBound(theArray) 'Should also be 500!!!
End Sub
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.