Board index » delphi » floating point arrays and C arrays - HELP ME

floating point arrays and C arrays - HELP ME

Greetings:

I am having a difficult time passing a floating point (single precision)
array from a Delphi application to a DLL written in C (MSVC 4.2 - using C
not C++).  I pass a pointer to the array, obtained with addr().  The code
looks something like this:

DLL

void FAR PASCAL _export DLLFunc(float*);

Delphi:

var
  array:array[0..100] of single;

procedure DLLFunc(p:pointer);far;

implementation
procedure DLLFunc;external 'dllname';

....
....
DLLFunc(addr(array));

The pointer that the DLL receives is the pointer returned by addr().
However, the DLL does not receive a pointer to the first element of the
array.  What am I missing?  Are pascal arrays padded with some header?

Thanks in advance for the help.
Dave

P.S.  Please do not reply to the e-mail address.  Send direct replies to
dlan...@ix.netcom.com or followup to this newsgroup.  Thanks again!

 

Re:floating point arrays and C arrays - HELP ME


Dr. David A. Landis wrote:

Quote

> Greetings:

> I am having a difficult time passing a floating point (single precision)
> array from a Delphi application to a DLL written in C (MSVC 4.2 - using C
> not C++).  I pass a pointer to the array, obtained with addr().  The code
> looks something like this:

> DLL

> void FAR PASCAL _export DLLFunc(float*);

> Delphi:

> var
>   array:array[0..100] of single;

> procedure DLLFunc(p:pointer);far;

> implementation
> procedure DLLFunc;external 'dllname';

> ....
> ....
> DLLFunc(addr(array));

> The pointer that the DLL receives is the pointer returned by addr().
> However, the DLL does not receive a pointer to the first element of the
> array.  What am I missing?  Are pascal arrays padded with some header?

        Is this the actual code you're using? Seems unlikely - Delphi
won't let me use "array" as an identifier. Seems like there could be
a problem with the actual code that we can't see. (I would use @x in
place of addr(x), but when I try it addr(x) seems to do the same thing.)

        How do you _know_ the dll's getting the wrong address? There's
no mysterious header; if I have x:array[0..10] of double then @x=@x[0],
as you'd expect.

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:floating point arrays and C arrays - HELP ME


On 26 Nov 1996 01:22:52 GMT, "Dr. David A. Landis"

Quote
<do.not.re...@this.address> wrote:
>I am having a difficult time passing a floating point (single precision)
>array from a Delphi application to a DLL written in C (MSVC 4.2 - using C
>not C++).  I pass a pointer to the array, obtained with addr().  The code
>looks something like this:

>DLL

>void FAR PASCAL _export DLLFunc(float*);

>Delphi:

>var
>  array:array[0..100] of single;

>procedure DLLFunc(p:pointer);far;

>implementation
>procedure DLLFunc;external 'dllname';
>....
>DLLFunc(addr(array));

>The pointer that the DLL receives is the pointer returned by addr().
>However, the DLL does not receive a pointer to the first element of the
>array.  What am I missing?  Are pascal arrays padded with some header?

If you are using Delphi 2, you should change the calling convention to
stdcall.

procedure DLLFunc(p:pointer); stdcall;

I don't know much more about C, and I cannot tell you if float=single.
Anyway, I assume there must be some integer passed indicating the size
of the array (or the size is fixed).

Hope this helps.
  Meikel Weber
make sure you visit my homepage
http://ourworld.compuserve.com/Homepages/meikel/mew.htm
When replying via E-Mail, strip the "*" in front of my address

Other Threads