fix: rebuild MES as compilable go-zero+ent backend (renamed bj_power_mes), restore 3 workstation projects from pristine original, align naming; all Go projects go build clean
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var (
|
||||
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
procCreateMutex = modkernel32.NewProc("CreateMutexW")
|
||||
procCloseHandle = modkernel32.NewProc("CloseHandle")
|
||||
user32 = syscall.NewLazyDLL("user32.dll")
|
||||
procMessageBox = user32.NewProc("MessageBoxW")
|
||||
)
|
||||
|
||||
const MB_OK = 0x00000000
|
||||
|
||||
const MB_ICONWARNING = 0x00000030
|
||||
|
||||
func MessageBox(title, msg string) {
|
||||
procMessageBox.Call(
|
||||
0,
|
||||
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(msg))),
|
||||
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))),
|
||||
MB_OK|MB_ICONWARNING,
|
||||
)
|
||||
}
|
||||
|
||||
var ErrAlreadyExists = fmt.Errorf("程序已在运行")
|
||||
|
||||
func createMutex(name string) (uintptr, error) {
|
||||
n, _ := syscall.UTF16PtrFromString(name)
|
||||
|
||||
r, _, err := procCreateMutex.Call(
|
||||
0,
|
||||
0,
|
||||
uintptr(unsafe.Pointer(n)),
|
||||
)
|
||||
|
||||
if r == 0 {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if errno, ok := err.(syscall.Errno); ok && errno == 183 { // ERROR_ALREADY_EXISTS
|
||||
return 0, ErrAlreadyExists
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func lock() {
|
||||
mutex, err := createMutex("back_cover_mutex")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer procCloseHandle.Call(mutex)
|
||||
}
|
||||
Reference in New Issue
Block a user