-
Notifications
You must be signed in to change notification settings - Fork 35
/
exportgo.go
38 lines (29 loc) · 839 Bytes
/
exportgo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
GoLang DLL example. Goals: load golang dll into fpc/lazarus, and load golang
dll into another go executable.
The syntax
//export SomeFunc
needs to be used above the function you want to export
To compile this program run:
go build -buildmode=c-archive exportgo.go
then compile goDLL.c that exports the functions for GCC to link, and run:
gcc -shared -pthread -o goDLL.dll goDLL.c exportgo.a -lWinMM -lntdll -lWS2_32
*/
package main
import "C"
import "fmt"
//export GetIntFromDLL
func GetIntFromDLL() int32 {
return 42
}
//export PrintHello
func PrintHello(name string) {
fmt.Printf("From DLL: Hello, %s!\n", name)
}
//export PrintBye
func PrintBye() {
fmt.Println("From DLL: Bye!")
}
func main() {
// Need a main function to make CGO compile package as C shared library
}