How to handle a return pointer to an array from a DLL 
Author Message
 How to handle a return pointer to an array from a DLL

Just copy it back into a VB array.

Redim yourarray(0 To numelements - 1)
CopyMemory ByRef yourarray(0), ByVal ptr, ByVal numelements * sizeof(single)

You cannot change the address of a VB array, so you'll have to copy it
if you do not want to pass the array by ref.

To receive the pointer from your C function, pass a Long by Ref.

Hope this helps

Alexander Kienzle


Quote:
> I have a DLL function that returns a pointer to an array
> of single values,  how can I handle this function call in
> Visual Basic?  Can visual basic receive a pointer to an
> array from a DLL.  I know that I can pass a reference to a
> vb array to a DLL function, but can it work the other way
> around?

> Thanks



Tue, 16 Dec 2003 21:39:00 GMT  
 How to handle a return pointer to an array from a DLL

You have to create and dimension an array. Then, pass the first byte of the array as a parameter. So your code will look something like this:

    Dim MyArray() as Byte

    Redim MyArray(1024)
    SomeAPIFunction MyArray(0)

--
Hans Blomme

Quote:

> I have a DLL function that returns a pointer to an array
> of single values,  how can I handle this function call in
> Visual basic?  Can visual basic receive a pointer to an
> array from a DLL.  I know that I can pass a reference to a
> vb array to a DLL function, but can it work the other way
> around?

> Thanks



Tue, 16 Dec 2003 21:42:04 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Q: On returning array from C DLL + pointer addressing

2. Q: On returning array from C DLL + pointer addressing

3. Q: On returning array from C DLL + pointer addressing

4. Passing array from VB to DLL and returning array

5. Passing pointer to a pointer or pointer to a char to a dll

6. pointer return from DLL

7. return pointer from a C DLL?

8. Accessing pointer returned from C DLL

9. Pointers returned in calling DLL′s

10. Holding a pointer to a C++ object being returned from a DLL call

11. .DLL function returns pointer to a double?

12. dll functions that return pointers to strings or structures

 

 
Powered by phpBB® Forum Software