使用 cgo 将字符串传递给 win32 函数

passing string to win32 function with cgo

我试试这个

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

但是编译不了

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

我尝试寻找类似的东西(例如 sqlite),但他们似乎使用相同的习惯用法,但它编译

尝试显式转换它:

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