Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows callback function in Golang

I wanna make push subscription to Windows Event Log in Golang
How exactly should I pass a callback function?

EVT_SUBSCRIBE_CALLBACK is the pointer of function, like

typedef DWORD ( WINAPI *EVT_SUBSCRIBE_CALLBACK)(
   EVT_SUBSCRIBE_NOTIFY_ACTION Action,
   PVOID                       UserContext,
   EVT_HANDLE                  Event
);

So, my variant looks like this:

func logCallback() syscall.Handle {

    cb := func(_ uintptr, _ uintptr, _ uintptr) uint64 {
        fmt.Printf("callback called %v", data)
        return 0
    }
    ptr := syscall.NewCallback(cb)
    return syscall.Handle(ptr) // type syscall.Handle uintptr
}

I get successfully subscribed handler with no errors, but it still doesn't work. Any ideas why? Where should I look first?

like image 926
ubombi Avatar asked Jul 07 '17 10:07

ubombi


1 Answers

When using syscall make sure the to include import "C" at the top of your file. Glad it helped you.

like image 121
reticentroot Avatar answered Nov 19 '22 19:11

reticentroot