[fpc-pascal] Extended float to single and pchar types

Urbansound urbansound at sbcglobal.net
Tue Aug 2 16:05:24 CEST 2005


Hi,

I have a stdcall reference to a c based dll. called target.dll
In c the setup is ...

float Get_l1_BidPriceSingle(void* p);

The Pascal reference is...

function Get_l1_BidPrice(p : pointer) : single;
stdcall; external 'target.dll' name 'Get_l1_BidPrice';

The end result is to allow a usage in win32 as ...
SendMessage(listbox, LB_ADDSTRING, 0, longint(Pchar(s)));

The c reference is  a 'Single' float, but each time I make refernece to data 
conversion, errors tell me that the reference to the call is returning a 10 
bit "Extended" float which fails, appearing to be a default autotype 
conversions to an extended 10 byte float, in fpc.

Converted data as an "Ansistring" seems to fail any type of conversion, as a 
runtime 207 crash.

If I store Str conversions to a "shortstring", I can format the fp and 
convert it to a fixed decimal rounded output, xxx.yyy, but using length() 
direct or pointer access, still pulls the 0 byte and extra characters of the 
string into any other converted output, requiring array managment and 
parsing.

Is there a way to take an "extended" FP and covert it ultimately to a Pchar 
that would allow messaging to win32 list boxes or similar to a litteral 
equivelent behaviour, without having to run through all the symantics of 
array management?

OR

Can one circumvent the auto-typing to extended, so that single or double 
would behave to conversion methods like FloatToStr() that I could then type 
over to pchar and serve the same purpose?

Clearly I'm not yet comfortable with string manipulation in Pascal, so an 
example would go a long way toward getting me to where I can do the work 
myself.

Thanks as always.

Mike 





More information about the fpc-pascal mailing list