Passing VB pointer to C Short Array (via void *) 
Author Message
 Passing VB pointer to C Short Array (via void *)

I have a C DLL defined as below...

   long stdcall crap(void *array)

I have a VB array defined below...

  Dim array as Integer

What is the VB prototype necessary to properly pass the address of the VB
array to the C function so the array can be modified?  I am assuming that I
simply recast the void* to a short* to read/write array entries (the DLL is
a third party DLL and I have tried several way but have no success.
However, I can pass it values if I use Visual C.)  Thanks. Bob



Fri, 14 May 2004 13:20:57 GMT  
 Passing VB pointer to C Short Array (via void *)
declare array at VB side like
dim array as variant

and try

-vinod


Quote:
> I have a C DLL defined as below...

>    long stdcall crap(void *array)

> I have a VB array defined below...

>   Dim array as Integer

> What is the VB prototype necessary to properly pass the address of the VB
> array to the C function so the array can be modified?  I am assuming that
I
> simply recast the void* to a short* to read/write array entries (the DLL
is
> a third party DLL and I have tried several way but have no success.
> However, I can pass it values if I use Visual C.)  Thanks. Bob



Sat, 15 May 2004 03:13:20 GMT  
 Passing VB pointer to C Short Array (via void *)
IIRC, VB arrays are actually COM SAFEARRAY's. If you control the source to
the DLL, you'll need to redefine it to take a SAFEARRAY, otherwise, you'll
need to write an intermediate DLL to do the translation for you.


Quote:
> I have a C DLL defined as below...

>    long stdcall crap(void *array)

> I have a VB array defined below...

>   Dim array as Integer

> What is the VB prototype necessary to properly pass the address of the VB
> array to the C function so the array can be modified?  I am assuming that
I
> simply recast the void* to a short* to read/write array entries (the DLL
is
> a third party DLL and I have tried several way but have no success.
> However, I can pass it values if I use Visual C.)  Thanks. Bob



Sat, 15 May 2004 03:36:13 GMT  
 Passing VB pointer to C Short Array (via void *)
You have two options
either to pass the array,in that case you need to use SAFEARRAY
or to pass the address of the first item in the array

search  for vb4dll.txt or vb4dll.exe on the internet
it   is a document which explain VB and C DLL-great stuff.still relvant.

tomer


Quote:
> IIRC, VB arrays are actually COM SAFEARRAY's. If you control the source to
> the DLL, you'll need to redefine it to take a SAFEARRAY, otherwise, you'll
> need to write an intermediate DLL to do the translation for you.



> > I have a C DLL defined as below...

> >    long stdcall crap(void *array)

> > I have a VB array defined below...

> >   Dim array as Integer

> > What is the VB prototype necessary to properly pass the address of the
VB
> > array to the C function so the array can be modified?  I am assuming
that
> I
> > simply recast the void* to a short* to read/write array entries (the DLL
> is
> > a third party DLL and I have tried several way but have no success.
> > However, I can pass it values if I use Visual C.)  Thanks. Bob



Sat, 15 May 2004 13:51:48 GMT  
 Passing VB pointer to C Short Array (via void *)
Try using the Any datatype:

    Declare Function {*filter*}Lib "Crap.dll" (ByRef array As Any) As Long

Then you can pass any datatype you want in. To pass in an array, do the
following:

    Dim array() As Integer
    .
    .
    .
    {*filter*}array(0) ' This will pass the pointer to the first element, which
is how C deals with arrays

Be careful how you manipulate the memory when you do this.
--
Michael "The" Gnter, MCSD, MCP (VC++, VB)
Senior Software Engineer
Infinity Software Development, Inc.
Phone: (850) 383-1011 . Fax: (850) 383-1015


Quote:
> I have a C DLL defined as below...

>    long stdcall crap(void *array)

> I have a VB array defined below...

>   Dim array as Integer

> What is the VB prototype necessary to properly pass the address of the VB
> array to the C function so the array can be modified?  I am assuming that
I
> simply recast the void* to a short* to read/write array entries (the DLL
is
> a third party DLL and I have tried several way but have no success.
> However, I can pass it values if I use Visual C.)  Thanks. Bob



Sat, 15 May 2004 02:46:03 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Pass a void pointer?

2. C DLL header conversion to VB - void pointers?

3. PB/DLL passing multidimensional VB arrays by pointers

4. VB, C++ Builder and passing arrays and file pointers

5. Passing an array of Strings to VB via ActiveX

6. Passing pointer to pointer to C struct from VB into a DLL

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

8. void pointers in dlls

9. void pointers in dlls

10. Passing Arrays Pointer To API

11. Passing in a pointer to an array of bytes

12. Arguments pass short 8.3 filename, how pass LFN?

 

 
Powered by phpBB® Forum Software