Golang 1.10 was released today or yesterday so I thought I would revisit this topic.
I was able to get a simple function written in Golang built as a Windows DLL and successfully call it from within a Xojo console app having declared it as a function.
Creating the dll using go does require gcc to be installed on the windows dev system.
This was a rough and ready simple first test that outputs a line of text, I will run additional tests in the future as I now look at golang to supplement my programs.
This opens up a whole new world of ‘back end’ functionality with Xojo as a front end.
Simple proof of concept :
64 bit Windows console app run event :
dim retval as integer
soft Declare function HelloWorld Lib "O:\\go\\dlltest\\hello.dll" () as integer
print "After declare"
retval = HelloWorld()
print "After function call to go dll...."
hello.go
package main
import "fmt"
import "C"
func main(){}
//export HelloWorld
func HelloWorld() int {
fmt.Println("This is output of the function in the golang created dll")
return 0
}
golang build command
go build -buildmode=c-shared -o hello.dll hello.go
Program output :
O:\\xojo\\dllgolang\\Builds - golangdll.xojo_project\\Windows 64 bit\\golangdll>golangdll
After declare
This is output of the function in the golang created dll
After function call to go dll....
O:\\xojo\\dllgolang\\Builds - golangdll.xojo_project\\Windows 64 bit\\golangdll>
At this most basic level it appears to work just fine, I will be exploring additional options in the future.
I guess things to look out for are which variable types match up, etc. Also - I’ve read that you should never ‘unload’ a golang dll.
I’ve already gone ‘64 bit only’ now which means that I really could do with that 64 bit windows debugger, any word on when we can expect that to be available ?