Solved

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

Posted on 1998-11-23
10
478 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
ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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