vladimirvivien / go-cshared-examples

Calling Go Functions from Other Languages using C Shared Libraries
MIT License
872 stars 112 forks source link

how execute csharp method from go c-shared library? #17

Open victorluk3 opened 4 years ago

victorluk3 commented 4 years ago

I tried use the a go library on csharp and use callbacks, but the application entire crash by the library with the error: unexpected fault address 0xffffffffffffffff fatal error: fault [signal 0xc0000005 code=0x0 addr=0xffffffffffffffff pc=0x627ca9ab]

go code:

package main

import "C"
import "fmt"

type externFunc func(int)

//export Connect
func Connect(fn externFunc) {
    fmt.Println("fn ",fn)

    for i:= 0; i<3;i++{
       fn(10)
    }

} 

How is the way to execute callbacks with c-shared?

vladimirvivien commented 4 years ago

My apologies, I do not know anything about CSharp. Cannot help.

vladimirvivien commented 4 years ago

See #18

victorluk3 commented 4 years ago

but the code in go, is the correct way to make callbacks?

vladimirvivien commented 4 years ago

I don't quite understand. The code is in csharp. Go offers one way for interoperability with external languages. I assume the csharp code is correct.