pass an array to a procedure
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
pass an array to a procedure
how do i pass an array to a procedure? i want to access all the float numbers i got in an array how can i pass the array to the procedure? i tried with @value at the procedure values but it gave me an error when trying to compile
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
i have an array with 4 values, they are color values (r,g,b etc). floats.
i have a procedure which needs the array to be passed because inside the procedure i call a dll which needs the array info (the colors).
i cant seem to pass the array correctly. my color is taken as green although what im sending is red.. and even if i have 0,0,0 its green anyway, i think im sending the pointer or something. how can i work arround this? is it even possible? how can i "fake" the array to the dll if not?
thanks!!!!
i have a procedure which needs the array to be passed because inside the procedure i call a dll which needs the array info (the colors).
i cant seem to pass the array correctly. my color is taken as green although what im sending is red.. and even if i have 0,0,0 its green anyway, i think im sending the pointer or something. how can i work arround this? is it even possible? how can i "fake" the array to the dll if not?
thanks!!!!
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
I don't know if I got your question right but maybe this helps (?)
I guess there will be more elegant ways for sure...
EDIT: Ah... too late again... didn't see your last response.
Code: Select all
Procedure showArray(*array.l)
For i=0 To 10
Debug PeekB(*array) ; PeekW(), PeekL(), PeekF()
*array+1 ; +2, +4
Next
EndProcedure
Dim myArray.b(10)
For i=0 To 10
myArray(i) = Random($FF)
Next
For i=0 To 10
Debug myArray(i)
Next
showArray(@myArray())
EDIT: Ah... too late again... didn't see your last response.
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
but if I use a for then I must call the dll function many times? this wont work!
and i managed to make it work but somehow it might be sending integers or something because i cant seem to mix the values, if i send 1,0,0 i get full red, thats ok ! but if i send 0.1,0,0 i still get full red! weird!!! if i send 0.1,0.1,0.5 i dont get a blueish color at all, its white!.
this is like what im doing:
and i managed to make it work but somehow it might be sending integers or something because i cant seem to mix the values, if i send 1,0,0 i get full red, thats ok ! but if i send 0.1,0,0 i still get full red! weird!!! if i send 0.1,0.1,0.5 i dont get a blueish color at all, its white!.
this is like what im doing:
Code: Select all
;my array
Dim Color.f(4)
Color(0) = R.f
Color(1) = G.f
Color(2) = b.f
Color(3) = 0.0
;this is my function
Procedure MyFunction(*value.f )
Dim TempArray.f(4)
TempArray() = *value.f
CallFunctionFast(*thefunction, TempArray() )
EndProcedure
;now im calling my function
MyFunction( Color() )
Now that I see what you're up to, why don't you simply pass the pointer on?
I mean, an array is nothing else than an "easy to handle memoryarea".
BTW: You're working with pointers here, a pointer can't be a float.
It should be MyFunction(*value.l).
I mean, an array is nothing else than an "easy to handle memoryarea".
BTW: You're working with pointers here, a pointer can't be a float.
It should be MyFunction(*value.l).
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
-
doodlemunch
- Enthusiast

- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
doodlemunch:
What DLL is that you're using?
Does it work outside your procedure, like
?
If it does, it should also work like this from your procedure:
There's no need to copy the values to a new array.
Both are using floats as color-values
SCNR 
What DLL is that you're using?
Does it work outside your procedure, like
Code: Select all
CallFunctionFast(*thefunction, @yourArray())
If it does, it should also work like this from your procedure:
Code: Select all
Procedure MyFunction(*colorArray.l )
CallFunctionFast(*thefunction, *colorArray)
EndProcedure
Hmm... last time I checked, OpenGL and DirectX were considered 'normal'.srod wrote:I only ask because colours are normally represented by 'long' datatypes.
Both are using floats as color-values
Good programmers don't comment their code. It was hard to write, should be hard to read.
Ah, not a great one for graphics me! Was talking with experience of PB and basic GDI only. Just making sure the problem was nothing obvious; usually is in my case!
I second your comments about the arrays and their being no need to copy the elements across to a new array etc.
I second your comments about the arrays and their being no need to copy the elements across to a new array etc.
I may look like a mule, but I'm not a complete ass.

