Forum > General
I have created dll in golang want to use inside lazarus freepascal
Packs:
--- Code: C [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---package main import "C"import ( "fmt" "math") // export RoundFloatfunc RoundFloat(val float64, precision uint) float64 { ratio := math.Pow(10, float64(precision)) return math.Round(val*ratio) / ratio} func main() {}
this is the command for compile the code in golang
go build -o easy.dll -buildmode=c-shared main.go
I would like to use the dll inside the lazarus free pascal
Zvoni:
What'S the calling convention? cdecl? Something else?
srvaldez:
in line 10 you have: // export RoundFloat
you need to remove the space between // and export otherwise it will not export the function
srvaldez:
example
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$h+} program easy_dll_test; function RoundFloat(x:double; prec:integer): double; cdecl; external 'easy' name 'RoundFloat'; var x, y:double; prec:integer; begin x:=3.1415926535897932; prec:=4; y:=RoundFloat(x, prec); writeln(y);end.
output: 3.1415999999999999E+000
Packs:
Thank you .
It is working
function abcRoundFloat(val: Double; precision: UInt8) :Double ; external 'easy.dll' name 'RoundFloat';
Y := abcRoundFloat(12.345,2);
Navigation
[0] Message Index
[#] Next page