diff --git a/kernel32.go b/kernel32.go index b08a9f62..ec51e505 100644 --- a/kernel32.go +++ b/kernel32.go @@ -73,6 +73,7 @@ var ( setLastError uintptr systemTimeToFileTime uintptr getProfileString uintptr + createMutex uintptr ) type ( @@ -109,6 +110,12 @@ type SYSTEMTIME struct { WMilliseconds uint16 } +type SECURITY_ATTRIBUTES struct { + NLength uint32 + LPSecurityDescriptor *uint16 + BInheritHandle bool +} + func init() { // Library libkernel32 = MustLoadLibrary("kernel32.dll") @@ -132,7 +139,7 @@ func init() { mulDiv = MustGetProcAddress(libkernel32, "MulDiv") setLastError = MustGetProcAddress(libkernel32, "SetLastError") systemTimeToFileTime = MustGetProcAddress(libkernel32, "SystemTimeToFileTime") - + createMutex = MustGetProcAddress(libkernel32, "CreateMutexW") } func CloseHandle(hObject HANDLE) bool { @@ -299,3 +306,19 @@ func SystemTimeToFileTime(lpSystemTime *SYSTEMTIME, lpFileTime *FILETIME) bool { return ret != 0 } + +func CreateMutex(lpMutexAttributes *SECURITY_ATTRIBUTES, bInitialOwner bool, lpName *uint16) (HANDLE, syscall.Errno) { + ret, _, err := syscall.Syscall(createMutex, 3, + uintptr(unsafe.Pointer(lpMutexAttributes)), + uintptr(boolToInt(bInitialOwner)), + uintptr(unsafe.Pointer(lpName))) + + return HANDLE(ret), err +} + +func boolToInt(b bool) int { + if b { + return 1 + } + return 0 +} diff --git a/user32.go b/user32.go index d6636472..6c68bd88 100644 --- a/user32.go +++ b/user32.go @@ -1485,6 +1485,7 @@ var ( killTimer uintptr loadCursor uintptr loadIcon uintptr + loadBitmap uintptr loadImage uintptr loadMenu uintptr loadString uintptr @@ -1603,6 +1604,7 @@ func init() { killTimer = MustGetProcAddress(libuser32, "KillTimer") loadCursor = MustGetProcAddress(libuser32, "LoadCursorW") loadIcon = MustGetProcAddress(libuser32, "LoadIconW") + loadBitmap = MustGetProcAddress(libuser32, "LoadBitmapW") loadImage = MustGetProcAddress(libuser32, "LoadImageW") loadMenu = MustGetProcAddress(libuser32, "LoadMenuW") loadString = MustGetProcAddress(libuser32, "LoadStringW") @@ -2226,6 +2228,15 @@ func LoadIcon(hInstance HINSTANCE, lpIconName *uint16) HICON { return HICON(ret) } +func LoadBitmap(hInstance HINSTANCE, lpBitmapName *uint16) HBITMAP { + ret, _, _ := syscall.Syscall(loadBitmap, 2, + uintptr(hInstance), + uintptr(unsafe.Pointer(lpBitmapName)), + 0) + + return HBITMAP(ret) +} + func LoadImage(hinst HINSTANCE, lpszName *uint16, uType uint32, cxDesired, cyDesired int32, fuLoad uint32) HANDLE { ret, _, _ := syscall.Syscall6(loadImage, 6, uintptr(hinst),