Passing arrays to dll's 
Author Message
 Passing arrays to dll's

Hi!

How can I pass an array to a dll from some index on:  dllcall(Len,a[Index]);
I know I have to somehow pin down the pointer, but I have no idea how to
obtain a pointer to the element within the array.

Thanks!
Janez.



Sun, 22 May 2005 18:53:51 GMT  
 Passing arrays to dll's
Janez,

    Actually, you want to pass this I believe:

dllcall(Len, &a[Index])

    If you use your call, you will be passing a single value, which is not
what you want.

    In C#, there isn't an easy way to do this, as you can't get an address
to pass through.  You have two options.  The first would be to use unsafe
code and pass the pointer to the element in the array (which you are allowed
to do in unsafe code).  If unsafe code is not an option, then I would copy
the elements from the array into a smaller array and pass the smaller array.
You can use the Buffer class to do a quick copy of the array section.

    Hope this helps.

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> Hi!

> How can I pass an array to a dll from some index on:

dllcall(Len,a[Index]);
Quote:
> I know I have to somehow pin down the pointer, but I have no idea how to
> obtain a pointer to the element within the array.

> Thanks!
> Janez.



Sun, 22 May 2005 21:20:17 GMT  
 Passing arrays to dll's
Hi!

Quote:
>     Actually, you want to pass this I believe:

> dllcall(Len, &a[Index])

Yes,

Quote:
>     If you use your call, you will be passing a single value, which is not
> what you want.

>     In C#, there isn't an easy way to do this, as you can't get an address
> to pass through.  You have two options.  The first would be to use unsafe
> code and pass the pointer to the element in the array (which you are
allowed
> to do in unsafe code).

Yes thats it. Unsafe code is not an issue... But how?
(I can not copy the array, because that kills the point of passing a
subindex).
Thanks!
Janez.


Sun, 22 May 2005 22:14:47 GMT  
 Passing arrays to dll's
Janez,

    Well, if this is the case, then you will have to either copy the subset
of the array, or you will have to marshal the array yourself (passing an
IntPtr of the marshaled data to the function in the dll).

--
               - Nicholas Paldino [.NET/C# MVP]


Quote:
> Hi!
> >     Actually, you want to pass this I believe:

> > dllcall(Len, &a[Index])

> Yes,

> >     If you use your call, you will be passing a single value, which is
not
> > what you want.

> >     In C#, there isn't an easy way to do this, as you can't get an
address
> > to pass through.  You have two options.  The first would be to use
unsafe
> > code and pass the pointer to the element in the array (which you are
> allowed
> > to do in unsafe code).

> Yes thats it. Unsafe code is not an issue... But how?
> (I can not copy the array, because that kills the point of passing a
> subindex).
> Thanks!
> Janez.



Sun, 22 May 2005 22:15:48 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Writing dll's to be called from visual basic, and passing arrays

2. Passing large byte-array from C# to Delphi DLL

3. Passing VB arrays to a dll written in C

4. VB 3 passing arrays to MSVC 1.52 DLL

5. long array passed to DLL??

6. Passing Array to DLL

7. passing short array parameters to VC++ DLL in VB

8. function parameters to pass a VB string array to a C++ DLL

9. HOWTO: Pass VB UDT that contains an array to VC dll

10. Passing arrays from VBA to C++ dll

11. passing Array of Strings between a C/C++ DLL and VB

12. Passing Arrays to DLL routines written in VC

 

 
Powered by phpBB® Forum Software