|
Post by held12345 on Apr 3, 2023 11:51:11 GMT -5
Hi good afternoon. how do you create your own dll for liberty basic?
this is what a cdll looks like for me. Pass 2 values then multiply and output again.
lbb_dll.dll :
------------------------ ProcedureCDLL.l mult(a.l,b.l) wertl.l = a*b ProcedureReturn wertl.l EndProcedure
ProcedureCDLL.l div(a.l,b.l) wertl.l = a/b ProcedureReturn wertl.l EndProcedure
ProcedureCDLL.d multf(a.d,b.d) wertl.d = a*b ProcedureReturn wertl.d EndProcedure
ProcedureCDLL.d divf(a.d,b.d) wertl.d = a/b ProcedureReturn wertl.d EndProcedure
------------------------
how does the reception pleace of liberty basic look like and the value for printing.
thanks
greeting
OPEN "lbb_dll.dll" for dll as #handle
x=6789 y=107 calldll #handle, "mult" , x as long, y as long , erg as long print(erg)
x=erg y=107 calldll #handle, "div" , x as long, y as long , erg as long print(erg)
print
x=2.578 y=222.532 calldll #handle, "multf" , x as double, y as double , erg as double print(erg)
x=erg y=222.532 calldll #handle, "divf" , x as double, y as double , erg as double print(erg)
wait
Attachments:
|
|
|
Post by Brandon Parker on Apr 3, 2023 20:57:27 GMT -5
Just a word of caution, be careful sending "Double" values from LB to DLLs. You should force each value to actually be a Double prior to sending it. For instance, if your multiplication method in the DLL multiplies two numbers together such as "2.0" and "2.0" together then the result returned by the DLL will be the Double of that multiplication which would be "4.0", but when LB retrieves that value, it will automatically turn it into an integer "4". This is just how LB works... You will need to re-force the value back to a Double. Here are the functions I use to force variables to be floating-point... Open "lbb_dll.dll" For DLL As #myDLL
x=200.0 y=2.0 CallDLL #myDLL, "multf", x As double, y As double , erg As double print erg
x= Val(ConvertToDouble$(erg,1,5)) y=2.0 CallDLL #myDLL, "divf", x As double, y As double , erg As double print erg
Close #myDLL
'____________________________________________________________________________________________________________________ '____________________________________________________________________________________________________________________
Function ConvertToDouble$(value, integerPart, decimalPart) 'integerPart does not Limit the integer portion; included for future Limit functionality integerPart$ = string$("#", integerPart) decimalPart$ = string$("#", decimalPart) ConvertToDouble$ = Trim$(RemChar$(Using(integerPart$;".";decimalPart$, value), "%")) End Function
'____________________________________________________________________________________________________________________ '____________________________________________________________________________________________________________________
Function string$(myString$, numstring) For i = 1 To numstring string$ = string$ + myString$ Next i End Function One interesting thing for me here is that you have used "Print(erg)" in your code and it seems to work for printing to the MainWin on LB 4.5.1. I do not recall coming across this previously although I could be simply not remembering it. While this "Print(value)" form is not documented in the helpfile, it does seem to work, and so does "Print (value)" as well... {:0) Brandon Parker
|
|
|
Post by held12345 on Apr 4, 2023 1:57:32 GMT -5
hello thanks for help.
here one error : convertToDouble$ = Trim$(RemChar$(Using(integerPart$;".";decimalPart$, value), "%"))
liberty basic : 4.5.0
greeeting
Attachments:
|
|
|
Post by Brandon Parker on Apr 4, 2023 9:45:31 GMT -5
Did you not copy the string$() function into the code base?
Function string$(myString$, numstring) For i = 1 To numstring string$ = string$ + myString$ Next i End Function
{:0)
Brandon Parker
|
|
|
Post by held12345 on Apr 4, 2023 10:57:08 GMT -5
this is the error:
convertToDouble$ = Trim$(RemChar$(Using(integerPart$;".";decimalPart$, value), "%"))
Open "lbb_dll.dll" For DLL As #myDLL
x=200.0 y=2.0 CallDLL #myDLL, "multf", x As double, y As double , erg As double print erg
x= Val(ConvertToDouble$(erg,1,5)) y=2.0 CallDLL #myDLL, "divf", x As double, y As double , erg As double print erg
wait Function ConvertToDouble$(value, integerPart, decimalPart) 'integerPart does not Limit the integer portion; included for future Limit functionality integerPart$ = string$("#", integerPart) decimalPart$ = string$("#", decimalPart) convertToDouble$ = Trim$(RemChar$(Using(integerPart$;".";decimalPart$, value), "%")) End Function
Function string$(myString$, numstring) For i = 1 To numstring string$ = string$ + myString$ Next i End Function
|
|
|
Post by Brandon Parker on Apr 4, 2023 11:26:30 GMT -5
I see...
It appears that the variable return within the function has been changed. It should be "ConvertToDouble$" and NOT "convertToDouble$" as the return variable since the name of the function is thus. The example I provided above has it correct, so there must have been something changed on your end. Just capitalize the "C" in "ConvertToDouble$" and it should work.
{:0)
Brandon Parker
|
|
|
Post by held12345 on Apr 4, 2023 15:01:02 GMT -5
is error.
Open "lbb_dll.dll" For DLL As #myDLL
x=200.0 y=2.0 CallDLL #myDLL, "multf", x As double, y As double , erg As double print erg
x= Val(ConvertToDouble$(erg,1,5)) y=2.0 CallDLL #myDLL, "divf", x As double, y As double , erg As double print erg
Close #myDLL
'____________________________________________________________________________________________________________________ '____________________________________________________________________________________________________________________
Function ConvertToDouble$(value, integerPart, decimalPart) 'integerPart does not Limit the integer portion; included for future Limit functionality integerPart$ = string$("#", integerPart) decimalPart$ = string$("#", decimalPart) ConvertToDouble$ = Trim$(RemChar$(Using(integerPart$;".";decimalPart$, value), "%")) End Function
'____________________________________________________________________________________________________________________ '____________________________________________________________________________________________________________________
Function string$(myString$, numstring) For i = 1 To numstring string$ = string$ + myString$ Next i End Function
greeting
|
|