英文:
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),但它们似乎使用了相同的习惯用法,但可以编译通过。
英文:
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
答案1
得分: 0
尝试显式转换它:
name := C.CString("vds")
C.OpenService(scm, (*C.CHAR)(unsafe.Pointer(name)), C.DWORD(C.SC_MANAGER_ALL_ACCESS))
英文:
Try explicitly casting it:
name := C.CString("vds")
C.OpenService(scm, (*C.CHAR)(unsafe.Pointer(name)), C>DWORD(C.SC_MANAGER_ALL_ACCESS))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论