master
兔子 8 months ago
parent 20c63730c8
commit 0959dfb96a

@ -362,3 +362,40 @@ func GlobalAlloc(uFlags DWORD, dwBytes uintptr) (HGLOBAL, error) {
} }
return HGLOBAL(r), nil return HGLOBAL(r), nil
} }
func GlobalFree(hMem HGLOBAL) error {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return err
}
defer syscall.FreeLibrary(kernel32)
gf, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GlobalFree")
if err != nil {
return err
}
r, _, errno := syscall.Syscall(gf, 1, uintptr(hMem), 0, 0)
if r == 0 {
if errno != 0 {
return error(errno)
}
return syscall.EINVAL
}
return nil
}
func RtlMoveMemory(Destination, Source unsafe.Pointer, Length uintptr) error {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return err
}
defer syscall.FreeLibrary(kernel32)
rmv, err := syscall.GetProcAddress(syscall.Handle(kernel32), "RtlMoveMemory")
if err != nil {
return err
}
_, _, errno := syscall.Syscall(rmv, 3, uintptr(unsafe.Pointer(Destination)), uintptr(unsafe.Pointer(Source)), Length)
if errno != 0 {
return error(errno)
}
return nil
}

Loading…
Cancel
Save