Author Topic: QB64 interoperability with FreeBasic  (Read 4128 times)

0 Members and 1 Guest are viewing this topic.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
QB64 interoperability with FreeBasic
« on: January 24, 2022, 02:52:12 am »
in reference to https://qb64forum.alephc.xyz/index.php?topic=4585.msg139931#msg139931
it took bplus 4 hours to calculate the result, I tried it using the decfloat routines that I wrote in QB64 but after 4 hours I aborted the program, then I tried it with the Freebasic version and the result was calculated and printed to the console in .3 seconds, that's less than half a second
so I was thinking of making a dll in FreeBasic to be used in QB64 to that end I experimented passing a structure that contains a string, I succeeded in figuring out how to get the value from the string but when I tried the same method on just a string it failed
if a string is an element of a structure it's passed by reference but when a simple string is passed then it's passed by value as in char * but in a structure the first element of the string is a pointer to the string data followed by the string length

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: QB64 interoperability with FreeBasic
« Reply #1 on: January 24, 2022, 02:53:15 am »
@jack Try it again with a CHR$(0) at the end of your string.
Shuwatch!

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: QB64 interoperability with FreeBasic
« Reply #2 on: January 24, 2022, 03:43:21 am »
hello SpriggsySpriggs
I tried it but there was no difference, it's not a problem as long as you know how to deal with it, it just struck me as inconsistent.
if anyone cares to try my experiment here are the codes
FreeBasic code
myDll.bas
Code: [Select]
Type Bf  Field = 1
As Short sign
As Ulong  exponent
As ulong ptr mantissa
End Type

sub bftest(byval result as zstring ptr, byref x as bf) export
dim as zstring ptr string_data=cptr(zstring ptr,x.mantissa[1]*&h100000000+x.mantissa[0])
result[0]=string_data[0]
result[1]=string_data[1]
result[2]=string_data[2]
result[3]=string_data[3]
end sub
compile command: fbc64 -dll -w all -gen gcc -O 2 mydll.bas
QB64 code
test_dll.bas
Code: QB64: [Select]
  1. Dest Console
  2.  
  3. Type Bf
  4.     As Integer sign
  5.     As _Unsigned Long exponent
  6.     As String mantissa
  7.  
  8.  
  9.     Sub BFTEST (result As String, x As Bf)
  10.  
  11. Dim As Bf s
  12. s.mantissa = "abcd"
  13. a = Space$(2 * Len(s.mantissa)) + Chr$(0)
  14. BFTEST a, s
  15.  

Offline Richard

  • Seasoned Forum Regular
  • Posts: 364
    • View Profile
Re: QB64 interoperability with FreeBasic
« Reply #3 on: February 06, 2022, 11:21:00 pm »
@jack

I tried your simple test program on QB64 win10x64 using FreeBASIC-1.09.0-winlibs-gcc-9.3.0 to create myDLL.dll and the output was

abcd

as per what you mentioned.


Just for fun, I (unsuccessfully) tried to create a STATIC library to test out instead of the dll. I was NOT after a smaller or faster exe - just wanted something that would "work". I based my attempt on the following link(s)

https://www.freebasic.net/forum/viewtopic.php?t=27380

with the corresponding sub link

https://github.com/marpon/mem_exe_dll/blob/master/dll2lib_test_enc_64.bas

In my case, only an    .a    file was created (not an .o) and Geany (for me) could not do anything with the .a file (hence I could not create a STATIC lib file).


Have you any progress on resolving the issue as per your first post and/or  can you create a STATIC library equivalent of myDLL.dll?

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: QB64 interoperability with FreeBasic
« Reply #4 on: February 07, 2022, 12:32:17 am »
General note: a .a file is an archive file, which typically contains one or more .o object files. The linker is capable of pulling object files directly out of archives, otherwise you can examine them with the ar tool.

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: QB64 interoperability with FreeBasic
« Reply #5 on: February 07, 2022, 04:38:01 am »
Hi Richard
I have not pursued this any further, here lately have lost interest in programming but I think that to use a static lib produced by FreeBasic could be problematic
a static lib is not necessarily free of dependencies and chasing those dependencies could be a pain but aside from that you would need a *.h file with the functions prototype and that can be tricky, functions that have parameters of simple scalar types should be easy but structures can be problematic