From f17fe8d3fb00e094775733afd36ac1b010860718 Mon Sep 17 00:00:00 2001 From: liuyang Date: Fri, 7 Feb 2020 08:47:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ comctl32.go | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..2df91c0a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +go.sum diff --git a/comctl32.go b/comctl32.go index 144affa7..da83b466 100644 --- a/comctl32.go +++ b/comctl32.go @@ -236,7 +236,15 @@ const ( I_IMAGENONE = -2 ) -type HIMAGELIST HANDLE +type ( + HIMAGELIST HANDLE + WPARAM uintptr + UINT uint32 + LPARAM uintptr + UINT_PTR uintptr + DWORD_PTR uintptr + LRESULT uintptr +) type INITCOMMONCONTROLSEX struct { DwSize, DwICC uint32 From d8246fdf5734bd6d02161a1498993177034b270e Mon Sep 17 00:00:00 2001 From: liuyang Date: Thu, 5 Mar 2020 22:06:40 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=92=E6=96=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel32.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/kernel32.go b/kernel32.go index 4c9e512d..488cdcaa 100644 --- a/kernel32.go +++ b/kernel32.go @@ -87,6 +87,8 @@ var ( setLastError *windows.LazyProc sizeofResource *windows.LazyProc systemTimeToFileTime *windows.LazyProc + createMutexW *windows.LazyProc + releaseMutex *windows.LazyProc ) type ( @@ -173,6 +175,8 @@ func init() { setLastError = libkernel32.NewProc("SetLastError") sizeofResource = libkernel32.NewProc("SizeofResource") systemTimeToFileTime = libkernel32.NewProc("SystemTimeToFileTime") + createMutexW = libkernel32.NewProc("CreateMutexW") + releaseMutex = libkernel32.NewProc("ReleaseMutex") } func ActivateActCtx(ctx HANDLE) (uintptr, bool) { @@ -449,3 +453,13 @@ func SystemTimeToFileTime(lpSystemTime *SYSTEMTIME, lpFileTime *FILETIME) bool { return ret != 0 } + +func CreateMutex(attr uintptr, bInitialOwner BOOL, lpName string) (HANDLE, syscall.Errno) { + name, _ := syscall.UTF16PtrFromString(lpName) + h, _, err := syscall.Syscall(createMutexW.Addr(), 3, attr, uintptr(bInitialOwner), uintptr(unsafe.Pointer(name))) + return HANDLE(h), err +} +func ReleaseMutex(handle HANDLE) bool { + b, _, _ := syscall.Syscall(releaseMutex.Addr(), 1, uintptr(handle), 0, 0) + return b == TRUE +}