use FreeBasic DLL in PB
Posted: Mon Jun 20, 2022 9:52 pm
here's simple example of using a DLL made with FreeBasic
testFBDll.pb
FBdll.bas
you can get the 64-bit dll from https://drive.google.com/file/d/1Wb8W1v ... sp=sharing
testFBDll.pb
Code: Select all
OpenConsole()
Define FBLibrary.i
Prototype.i Add_Strings(*result.string, *a.string, *b.string)
Prototype.l Add_Longs(a.l, b.l)
Prototype.d Add_Doubles(a.d, b.d)
Prototype.q Add_Quads(a.q, b.q)
FBLibrary = OpenLibrary(#PB_Any, "FBdll.dll")
If FBLibrary
Global Add_Strings.i : Add_Strings.Add_Strings = GetFunction(FBLibrary, "Add_Strings")
Global Add_Longs.i : Add_Longs.Add_Longs = GetFunction(FBLibrary, "Add_Longs")
Global Add_Doubles.i : Add_Doubles.Add_Doubles = GetFunction(FBLibrary, "Add_Doubles")
Global Add_Quads.i : Add_Quads.Add_Quads = GetFunction(FBLibrary, "Add_Quads")
Else
PrintN("FBdll.dll not found")
Input()
End
EndIf
Define.s s, a, b
a="Καλώς ήρθατε στην"
b=" στην Purebasic"
s=Space(256)
Add_Strings(@s, @a, @b)
;MessageRequester(s,a+b)
PrintN(s)
PrintN(Str(Add_Longs(123456789, 987654321)))
PrintN(Str(Add_Doubles(222222222222222.0, 333333333333333.0)))
PrintN(Str(Add_Quads(4611686018427387903, 4611686018427387904)))
Input()
CloseConsole()
Code: Select all
#cmdline "-dll -t 4096 -w all -arch native -gen gcc -Wc -O2 -v"
Extern "Windows-ms"
Sub Add_Strings(Byval result As Wstring Ptr, Byval a As Wstring Ptr, Byval b As Wstring Ptr) Export
*result=*a+*b
End Sub
Function Add_Longs(Byval a As Long, Byval b As Long) As Long Export
Return a+b
End Function
Function Add_Doubles(Byval a As Double, Byval b As Double) As Double Export
Return a+b
End Function
Function Add_Quads(Byval a As Longint, Byval b As Longint) As Longint Export
Return a+b
End Function
End Extern