Dll usage in LibreOffice Basic with routines introduced by declare statements

For very special tasks I wrote a few lines of code in Pascal and compiled that into a dll (Win). I did this mainly to be able to directly access the RAM representation of numbers.(Dbl). It works neatly.with numbers or arrays of Bytes (e.g.). However, in the context I would like to be able to return results as strings. It’s not relevant for me if I get the them as function results or via transient parameters, but actually I dont know how to get strings at all.

FloatToStrF()?

I’m sorry, what is the exact question? Do you ask how to return strings from a DLL function? Or do you ask how to convert doubles to strings (which, again, needs clarification which format do you need? Do you want a base-two representation? hexadecimal? decimal? and if decimal, then rounded to N significant digits? exact? in scientific format? …)

It’s about the passing, not about the creation of the string. Bad: I forgot most of what I knew about Pascal some decades ago.
Background: For a kind of “academic experiment” I want to work with a string representation of Double allowing “lexicographic sorting”. I Can do it in Basic, but it would be some100 times faster in Pascal.
What I tried ended in breaking LibO. The string types seem to be inompatible.,

Quite some time ago…
.
Where in traditional C a string is actually only a pointer to some place in memory wich hopefully contains a \0 terminator Pascal knows the length of the string, so internally needs something like

BEGIN RECORD
  len: INTEGER;
  str: ARRAY [1..len] OF CHAR;
END;

But this is internal and may depend on your compiler, especially the size of INTEGER.
.
Second problem is Pascal allows Functions to call parameters by name VAR and value. So a string is either copied or you get a pointer to the actual RECORD/struct.
.
I’m not sure, if you could return a string as “result” of a function.
.
I guess you’d have to find out, what your compiler used on the pascal-side. Wich compiler did you use then? Delphi?

If you tried to return a Pascal string, did you make sure to null-terminate it before return?

Ah, of course you could only return a string if you leak it - allocate without releasing.

I know only slow way, transform the numerical values to string values character by character

	dim i&, s$
	for i=lbound(arr) to ubound(arr) 'your array of numbers
		s=s & chr(arr[i]) 'output string
	next i

That’s basically what I do provisionally with results passed via variables or function results typed array[indexrange] of byte, but that requires the slow loop in Basic. If I knew a compatible string type I would be able to pass the final “lexicographic” representation as a string.

I have experience only how to use readString from a TXT file, but what try to explore if is it possible to read data as Stream from array in memory and not only from a file?
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1io_1_1XInputStream.html
https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1io_1_1SequenceInputStream.html
There are methods readBytes, readSomeBytes, createStreamFromSequence, but I don’t know how to use it.

x= float(10/3)
bias = 1023
xfrac, exp = x.hex().split('p')
exp = int(exp)
frac = xfrac.split(".")[-1]
print(f'''sign: {x<0:n}, exponent: {exp},'''
      f'''fraction_hexadecimal: {frac}''')
print(f"""{x<0:n} {0 if exp<0 else ""}"""
      f"""{bias+exp:{'<011b' if exp>0 else '<010b'}} """
      f"""{int(frac,16):<052b}""")

## that prints:
sign: 0, exponent: 1,fraction_hexadecimal: aaaaaaaaaaaab
0 10000000000 1010101010101010101010101010101010101010101010101011