Unable to get floating-point value returned from syscallN

Hello Everyone,

I have a delphi dll with a function that return a fix float (real) value 88.88.

I unable get the floating-point returned value (88.88) with a syscallN function. I have tried some alternatives (r3, r4, r5 and r6 in the code below), but every them not work.

I am testing the second parameter returned as instructed in https://go-review.googlesource.com/c/go/+/236562/3/src/syscall/dll_windows.go#172.

I get the return of other types like: integer, string, but not float.

func main() {
	dll, error := syscall.LoadLibrary("PrismaIB.dll")
	if error != nil {
		log.Fatalf("Error syscall.LoadLibrary: %s\n", error)
	}

	defer syscall.FreeLibrary(dll)

	function, error := syscall.GetProcAddress(dll, "TestReturnFloat")
	if error != nil {
		log.Fatalf("Error syscall.GetProcAddress: %s\n", error)
	}

	r1, r2, nerror := syscall.SyscallN(uintptr(function))
	if nerror != 0 {
		log.Fatalf("Error syscall.SyscallN: %v\n", nerror)
	}

	r3 := math.Float32frombits(uint32(r2))
	r4 := float32(r2)
	r5 := uintptr(unsafe.Pointer(&r2))
	r6 := *(*float32)(unsafe.Pointer(&r2))

	fmt.Printf("\nresult-> r1: %v, r2: %v, r3: %v, r4: %v, r5: %v, r6: %v\n\n", r1, r2, r3, r4, r5, r6)
}

My go version is “go1.22.0 windows/amd64”

Thank you - André

1 Like