Re: How to pass 2-dimensional array to/from DLL?

From: Peter Below (TeamB) (100113.1101_at_compuXXserve.com)
Date: 10/09/03


Date: Thu, 09 Oct 2003 21:46:48 +0200

In article <3f846f34@newsgroups.borland.com>, Matthias Matting wrote:
> > You have already made that impossible by using the Delphi TStream type in
> > your exported functions.
>
> Ooops - I just browsed through the dev guide and websites and noticed that
> Delphi strings and dynamic arrays are "forbidden". So what should I use
> instead of TStream? I just need some basic data structure to exchange a lot
> of bytes with the DLL without knowing their exact number at compile time how
> many bytes. Any hint for what keyword I should look?

If you cannot ask the DLL up front how much memory it needs (in which you can
just allocate an array of byte large enough and pass the DLL the address of
the first element) you may use an IStream interface reference. Again most
languages used for Windows programming will be able to deal with that, since
it is a standard COM interface. Delphi has the TStreamAdapter
class that allows you to get an IStream interface for any TStream descendent.

> > This is a static array type, so it is possible to declare equivalent types
> in
> > other languages.
>
> Okay, so a one dimensional array would be okay? I could easily transform
> the two dimensional 320x200 array to a 64000 array of byte. Or is there some
> size limitation?

You don't get the point, i think. As long as the *data* to be put into the
buffer by the DLL is organized as a 2D array of bytes the layout issue is
relevant, regardless of how you type this parameter on the Delphi side. In
fact there is no problem on the Delphi side to type it as a static 2D array as
you have done now. It is the writer of the DLL that needs to be aware of how
he has to type the parameter on *his* side of the fence to get the correct
memory layout the caller expects. For C, for example, a parameter of type
PBytearray

> TByteArray = array[0..319,0..199] of byte;
> PByteArray = ^TByteArray;

would have to be translated as "byte Buffer[200,320]" if my meagre C knowledge
is correct.

--
Peter Below (TeamB)  
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be