go execute a callback(via function ptr) from dll

Viewed 18

I got a callback from a dll, the function ptr type defind:

typedef int32_t (WINAPI *fn) ();

if use cgo, we can do like this:

/*
#include <windows.h>
#include <stdint.h>

typedef int32_t (WINAPI *fn) ();

int32_t call_callback(fn f){
   f();
}
*/
import "C"
import (
    "unsafe"
)

func main() {

    var callBackPtr uintptr // from dll function

    C.call_callback(*(*C.fn)(unsafe.Pointer(callBackPtr)))

}

BUT! I don't want to use cgo. How can I achieve in pure go?

0 Answers
Related