![111111111111111111111111111111.png](https://static.studygolang.com/200508/f11e730d9e03c68dc75e301e84eb581f.png)
求大佬解决一下!!!
主要是用go调用CreateMutex函数然后用来判断是否程序运行,别说其它 方法实现,我需要的是调用这个函数!
更多评论
两种方式,第一种自己封装,第二种调用golang.org/x/sys/windows
```go
import (
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
const (
ERROR_ALREADY_EXISTS = 183
)
var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procCreateMutex = kernel32.NewProc("CreateMutexW")
)
func createMutex(name string) (uintptr, error) {
ret, _, err := procCreateMutex.Call(
0,
0,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(name))),
)
switch int(err.(syscall.Errno)) {
case 0:
return ret, nil
default:
return ret, err
}
}
func createMutexSys(name string) (windows.Handle, error) {
return windows.CreateMutex(nil, true, syscall.StringToUTF16Ptr(m))
}
```
#2