Search code examples
gocgo

passing string to win32 function with cgo


I try this

name := C.CString("vds")
C.OpenService(scm, (name), C.DWORD(C.SC_MANAGER_ALL_ACCESS))

but it wont compile

.\test.go:28: cannot use name (type *C.char) as type *C.CHAR in argument to _Cfunc_OpenService

I tried looking for similar things (sqlite for example) but they seem to use this same idiom, but it compiles


Solution

  • Try explicitly casting it:

    name := C.CString("vds")
    C.OpenService(scm, (*C.CHAR)(unsafe.Pointer(name)), C>DWORD(C.SC_MANAGER_ALL_ACCESS))