a slightly more useful example modeled after the UInt64 library from long ago
you may get the 64-bit dll from
https://drive.google.com/file/d/1daUh4v ... sp=sharing
Uint64-test.pb
Code: Select all
OpenConsole()
Define FBLibrary.i
Prototype.l Uint64_ulong2Uint64(a.l, *b.Quad)
Prototype.l Uint64_add(*a.Quad, *b.Quad, *result.Quad)
Prototype.l Uint64_sub(*a.Quad, *b.Quad, *result.Quad)
Prototype.l Uint64_mul(*a.Quad, *b.Quad, *result.Quad)
Prototype.l Uint64_div(*a.Quad, *b.Quad, *result.Quad)
Prototype.l Uint64_mod(*a.Quad, *b.Quad, *result.Quad)
Prototype.l Uint64_cmp(*a.Quad, *b.Quad)
Prototype.l Uint64_val(*a.string, *b.Quad)
Prototype.l Uint64_str(*b.Quad, *a.string)
FBLibrary = OpenLibrary(#PB_Any, "Uint64.dll")
If FBLibrary
Global Uint64_ulong2Uint64.i : Uint64_ulong2Uint64.Uint64_ulong2Uint64 = GetFunction(FBLibrary, "Uint64_ulong2Uint64")
Global Uint64_add.i : Uint64_add.Uint64_add = GetFunction(FBLibrary, "Uint64_add")
Global Uint64_sub.i : Uint64_sub.Uint64_sub = GetFunction(FBLibrary, "Uint64_sub")
Global Uint64_mul.i : Uint64_mul.Uint64_mul = GetFunction(FBLibrary, "Uint64_mul")
Global Uint64_div.i : Uint64_div.Uint64_div = GetFunction(FBLibrary, "Uint64_div")
Global Uint64_mod.i : Uint64_mod.Uint64_mod = GetFunction(FBLibrary, "Uint64_mod")
Global Uint64_cmp.i : Uint64_cmp.Uint64_cmp = GetFunction(FBLibrary, "Uint64_cmp")
Global Uint64_val.i : Uint64_val.Uint64_val = GetFunction(FBLibrary, "Uint64_val")
Global Uint64_str.i : Uint64_str.Uint64_str = GetFunction(FBLibrary, "Uint64_str")
Else
PrintN("Uint64.dll not found")
Input()
End
EndIf
a.Quad
b.Quad
c.Quad
Define.s s
;---------------------------------------------------
OpenConsole()
s="2000000000000" : UInt64_val(@s, a)
s="7" : UInt64_val(@s, b)
PrintN("A = 2000000000000")
PrintN("B = 7")
UInt64_add(a, b, c)
s=Space(64) : UInt64_str(c, @s) :PrintN("A + B = " + s)
Uint64_sub(a, b, c)
s=Space(64) : UInt64_str(c, @s) :PrintN("A - B = " + s)
UInt64_mul(a, b, c)
s=Space(64) : UInt64_str(c, @s) :PrintN("A * B = " + s)
UInt64_div(a, b, c)
s=Space(64) : UInt64_str(c, @s) :PrintN("A / B = " + s)
UInt64_mod(a, b, c)
s=Space(64) : UInt64_str(c, @s) : PrintN("A mod B = " + s)
result.l = UInt64_cmp(a, b) ; Result = 0 if a=b, -1 if a<b, 1 if a>b
PrintN("Compare A to B: (Return 0 if a=b, -1 if a<b, 1 if A>b) = " + Str(result))
PrintN("")
PrintN("Press Enter to Continue...")
Input()
CloseConsole()
End
Uint64.bas
Code: Select all
#cmdline "-dll -t 4096 -w all -arch native -gen gcc -Wc -O2 -v"
/'
Uint64 Library for PureBasic
----------------------------
'/
Type Uint64 As Ulongint Ptr
' Uint64 Ulong2Uint64 ------------------------------------------------------------
Extern "Windows-ms"
Function Uint64_ulong2Uint64(Byval a As Ulong, Byval b As Uint64) As Long Export
*b = Culngint(a)
Return 1
End Function
' Uint64 Add ------------------------------------------------------------------
Function Uint64_add(Byval a As Uint64, Byval b As Uint64, Byval result As Uint64) As Long Export
*result = *a + *b
Return 1
End Function
' Uint64 Subtract ------------------------------------------------------------------
Function Uint64_sub(Byval a As Uint64, Byval b As Uint64, Byval result As Uint64) As Long Export
*result = *a - *b
Return 1
End Function
' Uint64 Multiply ------------------------------------------------------------------
Function Uint64_mul(Byval a As Uint64, Byval b As Uint64, Byval result As Uint64) As Long Export
*result = *a * *b
Return 1
End Function
' Uint64 Divide ------------------------------------------------------------------
Function Uint64_div(Byval a As Uint64, Byval b As Uint64, Byval divresult As Uint64) As Long Export
*divresult = *a / *b
Return 1
End Function
' Uint64 Mod ------------------------------------------------------------------
Function Uint64_mod(Byval a As Uint64, Byval b As Uint64, Byval modresult As Uint64) As Long Export
*modresult = *a Mod *b
Return 1
End Function
' Uint64 Compare ------------------------------------------------------------------
Function Uint64_cmp(Byval a As Uint64, Byval b As Uint64) As Long Export
If (*a <> *b) Then
Return Iif(*a < *b ,-1, 1)
End If
Return 0
End Function
' String to Uint64 ------------------------------------------------------------------
Function Uint64_val(Byval mystring As Wstring Ptr, Byval a As Uint64) As Long Export
*a=Culngint(*mystring)
Return 1
End Function
' Uint64 to String ------------------------------------------------------------------
Function Uint64_str(Byval a As Uint64, Byval result_string As Wstring Ptr) As Long Export
Dim As Long length = Len(*result_string)
Dim As String v = Str(*a)
If (length*2+2)>=(Len(v)*2+2) Then
*result_string=v
Return 1
Else
Return 0
End If
End Function
end extern
example output
Code: Select all
A = 2000000000000
B = 7
A + B = 2000000000007
A - B = 1999999999993
A * B = 14000000000000
A / B = 285714285714
A mod B = 2
Compare A to B: (Return 0 if a=b, -1 if a<b, 1 if A>b) = 1