Solved

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

Posted on 1998-11-23
10
485 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

821 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