I think it wanted a pointer to a "memory buffer" (for storing an image)... I'll have to go back and make sure tomorrow. Will post to let you know if it worked
I am now trying to do something similiar to the first post, but with an array... varPtr, objPtr and strPtr don't appear to work for this. Is there a workaround?
Originally posted by chuddy The argument is actually of type short...
long blah(short FAR* Buffer)
(c++ short equiv. to vb Integer)
Have a problem...
The pointers that I am able to retrieve are all of type long, but the C++ interface requires it to be short.
CInt(pointer) does not appear to be allowed as this tries to convert the long into an Integer...
Any suggestions?
Thanks
You do in fact want a Long for your pointer. short refers to the data being pointed to, not the size of the pointer. Use VarPtr to get the address of the buffer and be sure to pass it ByVal to the C/C++ function - it is expecting the address of the buffer, not the address of the Long holding the buffer address.
Also, blah is going to return a Long so you will need an lvalue for that. VarPtr, ObjPtr & StrPtr also require an lvalue, which is most likely the reason for the errors that you mention in your last post.
I still cannot get it to work, but have a feeling that there may be a problem with the method. Within VB it's expecting me to pass an Integer through as the argument representing the pointer...
I can see this because of the "intelli" (ctrl + space) thing... feeding a Long in upsets the compiler as it's expecting an integer and attempting to cast the long (cInt(long value)) causes an overflow error.... am going to see wht the guys who wrote the stuff reckon.
Anyway, the little explanation below is very handy as I have to do several similar calls... Cheers!
[added later: isn't byVal varPtr(myArray(0)) equal to myArray(0)? (I can see it is not as my app crashes when I try to pass in myArray(0), but not the other method... not sure why though. Anybody know?)]
Last edited by chuddy; Dec 15th, 2003 at 06:43 AM.
Originally posted by chuddy [added later: isn't byVal varPtr(myArray(0)) equal to myArray(0)? (I can see it is not as my app crashes when I try to pass in myArray(0), but not the other method... not sure why though. Anybody know?)]
It should be since the default is ByRef.
I see that Merrion has already replied with the same suggestion that I was going to make. I wasn't sure what kind of type checking VB would do since we were passing a "pointer", but now that I think about it, it makes sense. I guess my C background got in the way this time. C doen't care how the data is defined as long as you cast it correctly.