Last active
October 8, 2021 22:58
-
-
Save justenwalker/30c0817c3f86cfe969f757098c8556d5 to your computer and use it in GitHub Desktop.
Calling Windows API from Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package win32 | |
import "syscall" | |
import "unsafe" | |
var ( | |
kernel32DLL = syscall.NewLazyDLL("kernel32.dll") | |
procCreateJobObjectA = kernel32DLL.NewProc("CreateJobObjectA") | |
) | |
// CreateJobObject uses the CreateJobObjectA Windows API Call to create and return a Handle to a new JobObject | |
func CreateJobObject(attr *syscall.SecurityAttributes, name string) (syscall.Handle, error) { | |
r1, _, err := procCreateJobObjectA.Call( | |
uintptr(unsafe.Pointer(attr)), | |
uintptr(unsafe.Pointer(StringToCharPtr(name))), | |
) | |
if err != syscall.Errno(0) { | |
return 0, err | |
} | |
return syscall.Handle(r1), nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment