简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM