title: Is it possible to return pointers to structs in go shared libraries?
body: <p>I'm experimenting with using Go for creating dlls in Windows that I can import into Python but I'm having some issues with exporting functions that return a pointer to a Go struct. The following is a very stripped down example:</p>
  
  <pre><code>package main
  
  import "C"
  
  type data struct {
      value1, value2 int
  }
  
  type PData *data
  
  //export Callme
  func Callme() PData {
      var d PData = new (data)
      return d
  }
  
  //export getValue1
  func getValue1 (st PData) int {
     return st.value1
  }
  
  func main() {
  }
  </code></pre>
  
  <p>Note I also create a pointer type hoping this would end up as a simple handle on the C side. For the C side to access the struct I would provide helper routines (I provide one example) on the go side that would take a pointer to the struct as an argument. Unfortunately, the above code doesn't compile:</p>
  
  <pre><code>go build -o main.dll -buildmode=c-shared .\main.go
  # command-line-arguments
  .\main.go:5:11: Go type not supported in export: struct {
       value1, value2 int
  }
  .\main.go:5:11: Go type not supported in export: struct {
      value1, value2 int
  }
  .\main.go:5:11: Go type not supported in export: struct {
      value1, value2 int
  }
  .\main.go:5:11: Go type not supported in export: struct {
      value1, value2 int
  }
  </code></pre>
  
  <p>Is this a limitation of Go? I've tried simple return values such as int and floats and they work ok.</p>
  
  <p>Is there any way around it?</p>