feat(dll): 自 go-hua 迁入 Windows 系统 API 封装
- 互斥体防多开/ShellExecute/窗口类名与标题查询/顶层窗口目录, 新增依赖 lxn/win - 仅 Windows, 附测试、examples/dll 例程与包 README
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// dll 包示例:Windows API 调用(互斥体防多开、ShellExecute、创建进程、窗口文本)
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
"git.zeroonesoft.cn/golib/zogo/dll"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 创建命名互斥体(常用于防止程序多开)
|
||||
handle, err := dll.CreateMutex(false, "go-hua-example-mutex")
|
||||
if err != nil {
|
||||
fmt.Println("CreateMutex 失败(可能已存在):", err)
|
||||
} else {
|
||||
fmt.Println("CreateMutex 成功, 句柄:", handle)
|
||||
}
|
||||
|
||||
// 打开已存在的互斥体
|
||||
h2, err := dll.OpenMutex(false, "go-hua-example-mutex")
|
||||
fmt.Println("OpenMutex:", h2, "错误:", err)
|
||||
|
||||
if handle != 0 {
|
||||
fmt.Println("ReleaseMutex:", dll.ReleaseMutex(handle))
|
||||
_ = syscall.CloseHandle(handle)
|
||||
}
|
||||
|
||||
// 以下功能会产生可见窗口,按需取消注释:
|
||||
//
|
||||
// 用系统默认程序打开网页/文件:
|
||||
// dll.ShellExecute("", "https://github.com", "", false)
|
||||
//
|
||||
// 创建进程(打开记事本):
|
||||
// dll.CreateProcess()
|
||||
//
|
||||
// 获取资源管理器当前打开的顶层路径:
|
||||
// path, err := dll.GetTopFolderPath()
|
||||
}
|
||||
Reference in New Issue
Block a user