Click to See Complete Forum and Search --> : Newbie question... accessing 2D arrays passed from VB
Jotaf98
Jun 7th, 2002, 10:04 AM
Hi all. I tried to make a DLL that needs to access some 2D arrays passed from VB (some of them are DX textures, others are simple 2D arrays [lookup tables]). Of course it didn't work :p
Can someone here please explain it to me? The way I did it was like this: *(PointerToFirstElement + Y * Width + X)
CornedBee
Jun 7th, 2002, 10:53 AM
I think VB arrays are sorted the other way round.
So VB
arr(x, y)
would be C
arr[y * width + x];
How do you have the function declared in VB, how in C, how do you call it?
parksie
Jun 7th, 2002, 01:12 PM
Search the forum for SAFEARRAY - I think this one's been asked before.
Jotaf98
Jun 8th, 2002, 05:14 PM
Huh... thanks, both of you... but... cornedbee that's exactly how I'm doing it (look at my code :p ) ... and parksie, I know about the SAFEARRAY type and that's why I'm passing a pointer to the raw data (item(0,0)).
Come on, it's not a hard question. I thought that anyone here could answer that. All I need is working code to access an array... obviously the one I'm using doesn't work :)
Btw is this legal in C++? arr[y * width + x]
parksie
Jun 8th, 2002, 06:52 PM
You can give whatever index into it you want, so that expression will be perfectly valid.
I have no idea what format VB tries to pass them as. You might be best off using ByVal ptr As Long in the Declare for the function, and then VarPtr(myarray(0)) as the argument when you call it.
Jotaf98
Jun 8th, 2002, 07:58 PM
Heh thanks :)
Well I used ByRef in the declaration... so I'm not using VarPtr... if it doesn't work I'll try that.
Btw I found the thread you were talking about... but I don't have the time to check it out now... well... I'll tell ya something later ok? :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.