Goland declares

I am trying to get data from a DLL compiled in golang, i have two functions, one that returns an integer and one a string (The local IP address) .

soft Declare function GetOutboundIP Lib “mydll.dll” () as Cstring
var result as string=GetOutboundIP()
system.debuglog result
**Code never gets here Xojo exits

The problem I have is Xojo exits when I call the fuction?
Anyone have any ideas?, I can pass and read integers ok. Is there any document that shows you how to convert the data from a DLL to Xojo?

Dave

What happens if you use a Ptr instead of a CString?

soft Declare function GetOutboundIP Lib "mydll.dll" () as Ptr
var result as MemoryBlock=GetOutboundIP()
If result <> Nil Then
  system.debuglog result.CString(0)
Else
  system.debuglog "Return value is null"
End If

This works ok:

package main
import "C"

//export HelloWorld
func HelloWorld() *C.char{
    return C.CString("Hello World!")
}

func main() {    
// Need a main function to make CGO compile package as C shared library
}
Declare Function HelloWorld Lib "C:\Users\Julian\Documents\Go\TestDLL\TestDLL.dll" () As CString
Dim s As CString = HelloWorld()
system.DebugLog(s)

Excelent! it works. Now to figure out arrays slices etc. Is there any documentation anywhere that explains all this?
Dave

Here’s an interesting question, when goland is running inside a dll declared by xojo, can it use all the threads / processors in a machine, as if its native?

Documentation - The Go Programming Language ?

I can’t see why not as long as you do things correctly. I know nothing about go so I can’t help I’m afraid. See here for more info A Tour of Go

Yeah, I know go and its pretty good at sharing load over CPU if you do it correctly, its just how does Xojo decide what it uses in place of go data types, in fact it looks more like the DLL uses C data types.

Sorry for the late reply to this. We’re using Xojo with Go and while I’m not an expert on it I know we are using CGo for the interface between the two. And IIRC it does limit what Go can do. I can ask our Go architect what the limitations are.

1 Like

interesting, you have any link about it ? thx

To cross the boundary between Go and another language you need to use CGo

Sadly there aren’t many tutorials that I know of for CGo, as it’s different than regular go. There are some decent blog posts on how to do it, but no real good how-tos. An Adventure into CGO — Calling Go code with C | by Ben McClelland | Medium

These are mostly comments made to me by our Go architect.

1 Like

Using CGo has limitations on memory management in the Go app. Not sure what those limitations are but no doubt those are brought up in the documentation.

1 Like