Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion kernel32.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var (
setLastError uintptr
systemTimeToFileTime uintptr
getProfileString uintptr
createMutex uintptr
)

type (
Expand Down Expand Up @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions user32.go
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ var (
killTimer uintptr
loadCursor uintptr
loadIcon uintptr
loadBitmap uintptr
loadImage uintptr
loadMenu uintptr
loadString uintptr
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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),
Expand Down