Solved

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

Posted on 1998-11-23
10
457 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now