Windows callback function in Golang
Asked Answered
B

1

8

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?

Bulley answered 7/7, 2017 at 10:21 Comment(3)
Looking for any answers.Bulley
If you get no errors.. then how are you measuring that it doesn't work? What is the expected functionality and what is happening? How are testing and debugging? Is this all the code... if not can you provide code that can be run local by the community. Are you importing c?? import "C" as the top line github.com/golang/go/issues/10973Anorthite
Yeah, that's it! Can u write it as answer. (Bounty)Bulley
A
3

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

Anorthite answered 11/7, 2017 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.