Solved

what is C float in Delphi? how to transfer parametrs by value?

Posted on 1998-11-23
10
504 Views
Last Modified: 2010-04-04
Hi,

I am trying to access a C .dll from Delphi.
If a function in the .dll receives "float" is it "Real" in Delphi?
if the C function recieves a pointer to float (float * fuu) what should be my decleration?

Thanks,
Tommy
0
Comment
Question by:tommyq
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1347709
A C float is a single in Delphi (ie 4byte IEEE float)

Your function would translate exactly to:

Type
  PtrFloat = ^Single;

procedure MyFunction(MyPtrFloatArg: PtrFloat);

However, if it is a pointer to a float because you want to modify the float and return it it will look like this:

procedure MyFunction(var MyArg : Single);

Cheers,

Raymond.  
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1347710
Oh yeah...

The complete declaration would look like this for the DLL protoype...

procedure MyFunction(var MyArg : Single); external 'TheDLL.DLL';

Cheers,

Raymond.
0
 

Author Comment

by:tommyq
ID: 1347711
Raymond,

Thanks for your prompt reply.
I'll try it out and let you know.

Tommy
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tommyq
ID: 1347712
Why can't I use Double?

Tommy

(Raymond, I am reopening the question only in order to get an answer)
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1347713
You can't use a double because it is 8 bytes in size. I may compile given that it is bigger than float, but you are definitely not guaranteed a sensible result.

If your app deals in doubles, then you could do some casting before and after calling the dll function.

Also, the complete declaration should be like this:
procedure MyFunction(PMyArg : ^Single); stdcall; external 'TheDLL.DLL';
It was missing the stdcall in Ray's solution.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1347714
The float constructor in C is exactly the same as the single type in Delphi. They use 4 bytes each.

You can also use the 8 bytes long floating point values known as double in both Delphi and C.

The delphi types float (6 bytes) and Extended (10 bytes) does not seem to be supported in C (Watcom v11.0)

/Williams
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1347715
Tommyq,

I believe my answer is the first correct one. Will you now select and accept an answer? (If you want to award the points to me you will need to reject Williams2 answer).

Cheers,

Raymond.
0
 
LVL 3

Expert Comment

by:williams2
ID: 1347716
Sorry Raymond,

You are absolutely right. I was a bit fast asnwering, and didn't read your comment.

So Toomyq, please reject my answer!

Regards,
Williams
0
 

Author Comment

by:tommyq
ID: 1347717
Rejecting in order to give points to Raymond.

Thank you Williams.
Raymond, come and collect your points!

Tommy
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1347718
Here I am!

Cheers,

Raymond.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question