|
-
Jun 7th, 2002, 10:04 AM
#1
Thread Starter
Frenzied Member
Newbie question... accessing 2D arrays passed from VB
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 
Can someone here please explain it to me? The way I did it was like this: *(PointerToFirstElement + Y * Width + X)
-
Jun 7th, 2002, 10:53 AM
#2
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?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jun 7th, 2002, 01:12 PM
#3
Monday Morning Lunatic
Search the forum for SAFEARRAY - I think this one's been asked before.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 8th, 2002, 05:14 PM
#4
Thread Starter
Frenzied Member
Huh... thanks, both of you... but... cornedbee that's exactly how I'm doing it (look at my code ) ... 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]
-
Jun 8th, 2002, 06:52 PM
#5
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 8th, 2002, 07:58 PM
#6
Thread Starter
Frenzied Member
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|