winapi

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Rendered for windows/amd64

Index

Constants

View Source
const (
	HKEY_LOCAL_MACHINE = 0x80000002
	KEY_READ           = 0x20019
)

HKEY values.

View Source
const (
	MIB_TCP_STATE_CLOSED     = 1
	MIB_TCP_STATE_LISTEN     = 2
	MIB_TCP_STATE_SYN_SENT   = 3
	MIB_TCP_STATE_SYN_RCVD   = 4
	MIB_TCP_STATE_ESTAB      = 5
	MIB_TCP_STATE_FIN_WAIT1  = 6
	MIB_TCP_STATE_FIN_WAIT2  = 7
	MIB_TCP_STATE_CLOSE_WAIT = 8
	MIB_TCP_STATE_CLOSING    = 9
	MIB_TCP_STATE_LAST_ACK   = 10
	MIB_TCP_STATE_TIME_WAIT  = 11
	MIB_TCP_STATE_DELETE_TCB = 12
)

TCP states (MIB_TCP_STATE_*).

View Source
const (
	TCP_TABLE_OWNER_PID_ALL = 5
	UDP_TABLE_OWNER_PID     = 1
)

TCP_TABLE_CLASS values for GetExtendedTcpTable.

View Source
const (
	TH32CS_SNAPPROCESS = 0x00000002
	TH32CS_SNAPTHREAD  = 0x00000004
)

CreateToolhelp32Snapshot flags.

View Source
const (
	JobObjectBasicLimitInformation     = 2
	JobObjectExtendedLimitInformation  = 9
	JobObjectCpuRateControlInformation = 15
)

Job Object information class values.

View Source
const (
	JOB_OBJECT_CPU_RATE_CONTROL_ENABLE   = 0x00000001
	JOB_OBJECT_CPU_RATE_CONTROL_HARD_CAP = 0x00000004
)

Job Object CPU rate control flags.

View Source
const (
	IDLE_PRIORITY_CLASS         = 0x00000040
	BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
	NORMAL_PRIORITY_CLASS       = 0x00000020
	ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000
	HIGH_PRIORITY_CLASS         = 0x00000080
	REALTIME_PRIORITY_CLASS     = 0x00000100
)

Priority class values.

View Source
const (
	NIM_ADD    = 0x00000000
	NIM_MODIFY = 0x00000001
	NIM_DELETE = 0x00000002

	NIF_MESSAGE = 0x00000001
	NIF_ICON    = 0x00000002
	NIF_TIP     = 0x00000004
	NIF_INFO    = 0x00000010

	NIIF_INFO    = 0x00000001
	NIIF_WARNING = 0x00000002
	NIIF_ERROR   = 0x00000003
)

Shell_NotifyIcon flags.

View Source
const (
	WM_USER          = 0x0400
	WM_TRAYICON      = WM_USER + 1
	WM_LBUTTONUP     = 0x0202
	WM_LBUTTONDBLCLK = 0x0203
	WM_RBUTTONUP     = 0x0205
	WM_COMMAND       = 0x0111
	WM_DESTROY       = 0x0002
)

Tray window message constants.

View Source
const (
	DRIVE_UNKNOWN   = 0
	DRIVE_REMOVABLE = 2
	DRIVE_FIXED     = 3
	DRIVE_REMOTE    = 4
)

Drive types.

View Source
const (
	AF_INET  = 2
	AF_INET6 = 23
)

Address families.

View Source
const (
	IDI_APPLICATION uintptr = 32512
	IDC_ARROW       uintptr = 32512
)

Stock icons / cursors.

View Source
const (
	TPM_LEFTALIGN   = 0x0000
	TPM_RIGHTBUTTON = 0x0002
	TPM_RETURNCMD   = 0x0100
)

TPM constants.

View Source
const HWND_MESSAGE = ^uintptr(2) //nolint:gocritic // 0xFFFFFFFD

HWND_MESSAGE for message-only windows.

View Source
const (
	JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
)

Job Object limit flags.

View Source
const (
	SW_SHOWNORMAL = 1
)

ShowWindow / ShellExecute constants.

View Source
const SystemProcessorPerformanceInformation = 8

Variables

This section is empty.

Functions

func AppendMenu

func AppendMenu(menu uintptr, flags, idNewItem uintptr, text string) error

AppendMenu adds an item to a menu.

func AssignProcessToJobObject

func AssignProcessToJobObject(job, proc windows.Handle) error

AssignProcessToJobObject assigns a process to a job.

func CloseHandleSafe

func CloseHandleSafe(h windows.Handle)

CloseHandleSafe closes a Windows handle ignoring errors.

func CollectQueryData added in v0.2.0

func CollectQueryData(query PdhQuery) error

CollectQueryData samples all counters attached to the PDH query.

func CreateJobObject

func CreateJobObject() (windows.Handle, error)

CreateJobObject creates an unnamed Job Object.

func CreatePopupMenu

func CreatePopupMenu() uintptr

CreatePopupMenu creates a popup menu.

func CreateToolhelp32Snapshot

func CreateToolhelp32Snapshot(flags, pid uint32) (windows.Handle, error)

CreateToolhelp32Snapshot creates a snapshot of system processes/threads/modules.

func CreateWindowEx

func CreateWindowEx(exStyle uint32, className, windowName *uint16, style uint32,
	x, y, width, height int32, parent uintptr, menu, instance uintptr,
	param unsafe.Pointer) (uintptr, error)

CreateWindowEx creates a window.

func DefWindowProc

func DefWindowProc(hwnd, msg, wParam, lParam uintptr) uintptr

DefWindowProc calls the default window procedure.

func DestroyMenu

func DestroyMenu(menu uintptr)

DestroyMenu destroys a menu.

func DestroyWindow

func DestroyWindow(hwnd uintptr)

DestroyWindow destroys a window.

func DispatchMessage

func DispatchMessage(msg *MSG) uintptr

DispatchMessage dispatches a message to a window procedure.

func FileTimeToUnix

func FileTimeToUnix(ft FILETIME) int64

FileTimeToUnix converts a Win32 FILETIME to a Unix timestamp (seconds).

func GetDiskFreeSpaceEx

func GetDiskFreeSpaceEx(path string) (freeAvail, totalBytes, totalFree uint64, err error)

GetDiskFreeSpaceEx retrieves available, total, and free space on a drive.

func GetDriveType

func GetDriveType(root string) uint32

GetDriveType returns the drive type (DRIVE_*) for a root path.

func GetFormattedCounterArrayDouble added in v0.2.0

func GetFormattedCounterArrayDouble(counter PdhCounter) (map[string]float64, error)

GetFormattedCounterArrayDouble returns the cooked values for a wildcard counter.

func GetLogicalDriveStrings

func GetLogicalDriveStrings() ([]string, error)

GetLogicalDriveStrings returns a list of drive root paths.

func GetMessage

func GetMessage(msg *MSG, hwnd uintptr) int32

GetMessage retrieves a message from the calling thread's queue.

func GetPriorityClass

func GetPriorityClass(h windows.Handle) (uint32, error)

GetPriorityClass returns a process's priority class.

func GetVolumeInformation

func GetVolumeInformation(root string) (label, fsName string)

GetVolumeInformation retrieves a drive's volume name and filesystem.

func IsProcessCritical

func IsProcessCritical(h windows.Handle) (bool, error)

IsProcessCritical reports whether a process is marked critical.

func LoadCursor

func LoadCursor(name uintptr) uintptr

LoadCursor loads a stock cursor (e.g., IDC_ARROW).

func LoadIcon

func LoadIcon(name uintptr) uintptr

LoadIcon loads a stock icon (e.g., IDI_APPLICATION).

func OpenProcessHandle

func OpenProcessHandle(access uint32, pid uint32) (windows.Handle, error)

OpenProcessHandle opens a process and returns a handle.

func OpenThreadHandle

func OpenThreadHandle(access uint32, threadID uint32) (windows.Handle, error)

OpenThreadHandle opens a thread and returns a handle.

func PostMessage

func PostMessage(hwnd uintptr, msg uint32, wParam, lParam uintptr)

PostMessage posts a message into the message queue of the specified window.

func PostQuitMessage

func PostQuitMessage(exitCode int32)

PostQuitMessage posts a WM_QUIT message.

func Process32First

func Process32First(snap windows.Handle, entry *PROCESSENTRY32W) error

Process32First retrieves the first process entry from a snapshot.

func Process32Next

func Process32Next(snap windows.Handle, entry *PROCESSENTRY32W) error

Process32Next retrieves the next process entry.

func QueryFullProcessImageName

func QueryFullProcessImageName(h windows.Handle) (string, error)

QueryFullProcessImageName retrieves a process's full executable path.

func RegReadDWORD

func RegReadDWORD(rootKey uintptr, subKey, value string) (uint32, error)

RegReadDWORD reads a DWORD registry value.

func RegReadQWORD added in v0.2.0

func RegReadQWORD(rootKey uintptr, subKey, value string) (uint64, error)

RegReadQWORD reads a QWORD registry value.

func RegReadString

func RegReadString(rootKey uintptr, subKey, value string) (string, error)

RegReadString reads a string registry value.

func RegisterClassEx

func RegisterClassEx(c *WNDCLASSEXW) (uint16, error)

RegisterClassEx registers a window class.

func ResumeThread

func ResumeThread(h windows.Handle) (uint32, error)

ResumeThread resumes a thread; returns previous suspend count.

func SetForegroundWindow

func SetForegroundWindow(hwnd uintptr)

SetForegroundWindow brings the specified window to the foreground.

func SetInformationJobObject

func SetInformationJobObject(job windows.Handle, infoClass uint32, info unsafe.Pointer, length uint32) error

SetInformationJobObject sets information on a Job Object.

func SetPriorityClass

func SetPriorityClass(h windows.Handle, class uint32) error

SetPriorityClass sets a process's priority class.

func SetProcessAffinityMask

func SetProcessAffinityMask(h windows.Handle, mask uintptr) error

SetProcessAffinityMask sets a process affinity mask.

func SetTipString

func SetTipString(dst []uint16, s string)

SetTipString writes text into a fixed-size uint16 array, NUL-terminating.

func ShellExecute

func ShellExecute(verb, file, params, dir string, show int32) error

ShellExecute opens or launches a file or URL.

func ShellNotifyIcon

func ShellNotifyIcon(message uint32, nid *NOTIFYICONDATAW) error

ShellNotifyIcon adds, modifies, or removes a notification area icon.

func SuspendThread

func SuspendThread(h windows.Handle) (uint32, error)

SuspendThread suspends a thread; returns previous suspend count.

func TerminateProcessHandle

func TerminateProcessHandle(h windows.Handle, exitCode uint32) error

TerminateProcessHandle terminates a process via handle.

func Thread32First

func Thread32First(snap windows.Handle, te *THREADENTRY32) error

Thread32First retrieves the first thread from a snapshot.

func Thread32Next

func Thread32Next(snap windows.Handle, te *THREADENTRY32) error

Thread32Next retrieves the next thread.

func TrackPopupMenu

func TrackPopupMenu(menu uintptr, flags uint32, x, y int32, hwnd uintptr) uintptr

TrackPopupMenu displays a popup menu.

func TranslateMessage

func TranslateMessage(msg *MSG)

TranslateMessage translates virtual-key messages.

Types

type FILETIME

type FILETIME struct {
	LowDateTime  uint32
	HighDateTime uint32
}

FILETIME is Win32 FILETIME (100ns ticks since 1601-01-01).

func GetProcessTimes

func GetProcessTimes(h windows.Handle) (creation, exit, kernel, user FILETIME, err error)

GetProcessTimes retrieves a process's creation/exit/kernel/user times.

func GetSystemTimes

func GetSystemTimes() (idle, kernel, user FILETIME, err error)

GetSystemTimes retrieves system idle/kernel/user FILETIMEs.

func (FILETIME) Ticks

func (ft FILETIME) Ticks() uint64

type IO_COUNTERS

type IO_COUNTERS struct {
	ReadOperationCount  uint64
	WriteOperationCount uint64
	OtherOperationCount uint64
	ReadTransferCount   uint64
	WriteTransferCount  uint64
	OtherTransferCount  uint64
}

IO_COUNTERS matches Win32 IO_COUNTERS.

func GetProcessIoCounters

func GetProcessIoCounters(h windows.Handle) (*IO_COUNTERS, error)

GetProcessIoCounters retrieves a process's I/O counters.

type IfRow2

type IfRow2 struct {
	Index        uint32
	Alias        string
	Description  string
	OperStatus   uint32
	Type         uint32
	SpeedRx      uint64
	SpeedTx      uint64
	InOctets     uint64
	OutOctets    uint64
	InUcastPkts  uint64
	OutUcastPkts uint64
	InErrors     uint64
	OutErrors    uint64
}

IfRow2 holds the fields we care about parsed from MIB_IF_ROW2.

func GetIfTable2

func GetIfTable2() ([]IfRow2, error)

GetIfTable2 returns the system network interface table. We let the Win32 API allocate a MIB_IF_TABLE2 buffer, walk the rows at their documented offsets, then free the buffer via FreeMibTable.

tablePtr is declared as unsafe.Pointer (not uintptr) so vet's unsafeptr analyzer is satisfied: we never do arithmetic on a uintptr and convert it back — all offsetting goes through unsafe.Add.

type JOBOBJECT_BASIC_LIMIT_INFORMATION

type JOBOBJECT_BASIC_LIMIT_INFORMATION struct {
	PerProcessUserTimeLimit int64
	PerJobUserTimeLimit     int64
	LimitFlags              uint32
	MinimumWorkingSetSize   uintptr
	MaximumWorkingSetSize   uintptr
	ActiveProcessLimit      uint32
	Affinity                uintptr
	PriorityClass           uint32
	SchedulingClass         uint32
}

JOBOBJECT_BASIC_LIMIT_INFORMATION matches Win32 struct.

type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION

type JOBOBJECT_CPU_RATE_CONTROL_INFORMATION struct {
	ControlFlags uint32
	CpuRate      uint32
}

JOBOBJECT_CPU_RATE_CONTROL_INFORMATION matches Win32 struct.

type JOBOBJECT_EXTENDED_LIMIT_INFORMATION

type JOBOBJECT_EXTENDED_LIMIT_INFORMATION struct {
	BasicLimitInformation JOBOBJECT_BASIC_LIMIT_INFORMATION
	IoInfo                IO_COUNTERS
	ProcessMemoryLimit    uintptr
	JobMemoryLimit        uintptr
	PeakProcessMemoryUsed uintptr
	PeakJobMemoryUsed     uintptr
}

JOBOBJECT_EXTENDED_LIMIT_INFORMATION matches Win32 struct.

type MEMORYSTATUSEX

type MEMORYSTATUSEX struct {
	Length               uint32
	MemoryLoad           uint32
	TotalPhys            uint64
	AvailPhys            uint64
	TotalPageFile        uint64
	AvailPageFile        uint64
	TotalVirtual         uint64
	AvailVirtual         uint64
	AvailExtendedVirtual uint64
}

MEMORYSTATUSEX matches Win32 MEMORYSTATUSEX.

func GlobalMemoryStatusEx

func GlobalMemoryStatusEx() (*MEMORYSTATUSEX, error)

GlobalMemoryStatusEx retrieves system memory information.

type MIB_TCP6ROW_OWNER_PID

type MIB_TCP6ROW_OWNER_PID struct {
	LocalAddr     [16]byte
	LocalScopeId  uint32
	LocalPort     uint32
	RemoteAddr    [16]byte
	RemoteScopeId uint32
	RemotePort    uint32
	State         uint32
	OwningPid     uint32
}

MIB_TCP6ROW_OWNER_PID matches Win32 IPv6 TCP row.

func GetTcp6Table

func GetTcp6Table() ([]MIB_TCP6ROW_OWNER_PID, error)

GetTcp6Table returns IPv6 TCP rows with owning PIDs.

type MIB_TCPROW_OWNER_PID

type MIB_TCPROW_OWNER_PID struct {
	State      uint32
	LocalAddr  uint32
	LocalPort  uint32
	RemoteAddr uint32
	RemotePort uint32
	OwningPid  uint32
}

MIB_TCPROW_OWNER_PID matches Win32 IPv4 TCP row.

func GetTcp4Table

func GetTcp4Table() ([]MIB_TCPROW_OWNER_PID, error)

GetTcp4Table returns IPv4 TCP rows with owning PIDs.

type MIB_UDP6ROW_OWNER_PID

type MIB_UDP6ROW_OWNER_PID struct {
	LocalAddr    [16]byte
	LocalScopeId uint32
	LocalPort    uint32
	OwningPid    uint32
}

MIB_UDP6ROW_OWNER_PID matches Win32 IPv6 UDP row.

func GetUdp6Table

func GetUdp6Table() ([]MIB_UDP6ROW_OWNER_PID, error)

GetUdp6Table returns IPv6 UDP rows with owning PIDs.

type MIB_UDPROW_OWNER_PID

type MIB_UDPROW_OWNER_PID struct {
	LocalAddr uint32
	LocalPort uint32
	OwningPid uint32
}

MIB_UDPROW_OWNER_PID matches Win32 IPv4 UDP row.

func GetUdp4Table

func GetUdp4Table() ([]MIB_UDPROW_OWNER_PID, error)

GetUdp4Table returns IPv4 UDP rows with owning PIDs.

type MSG

type MSG struct {
	Hwnd    uintptr
	Message uint32
	WParam  uintptr
	LParam  uintptr
	Time    uint32
	Pt      POINT
}

MSG struct used by message pump.

type NOTIFYICONDATAW

type NOTIFYICONDATAW struct {
	Size            uint32
	Wnd             uintptr
	ID              uint32
	Flags           uint32
	CallbackMessage uint32
	Icon            uintptr
	Tip             [128]uint16
	State           uint32
	StateMask       uint32
	Info            [256]uint16
	Union           uint32
	InfoTitle       [64]uint16
	InfoFlags       uint32
	GuidItem        [16]byte
	BalloonIcon     uintptr
}

NOTIFYICONDATAW matches Win32 NOTIFYICONDATAW.

type POINT

type POINT struct {
	X int32
	Y int32
}

POINT struct (cursor position).

func GetCursorPos

func GetCursorPos() (POINT, error)

GetCursorPos retrieves the cursor position.

type PROCESSENTRY32W

type PROCESSENTRY32W struct {
	Size            uint32
	Usage           uint32
	ProcessID       uint32
	DefaultHeapID   uintptr
	ModuleID        uint32
	Threads         uint32
	ParentProcessID uint32
	PriClassBase    int32
	Flags           uint32
	ExeFile         [260]uint16
}

PROCESSENTRY32W matches Win32 PROCESSENTRY32W.

type PROCESS_MEMORY_COUNTERS_EX

type PROCESS_MEMORY_COUNTERS_EX struct {
	CB                         uint32
	PageFaultCount             uint32
	PeakWorkingSetSize         uintptr
	WorkingSetSize             uintptr
	QuotaPeakPagedPoolUsage    uintptr
	QuotaPagedPoolUsage        uintptr
	QuotaPeakNonPagedPoolUsage uintptr
	QuotaNonPagedPoolUsage     uintptr
	PagefileUsage              uintptr
	PeakPagefileUsage          uintptr
	PrivateUsage               uintptr
}

PROCESS_MEMORY_COUNTERS_EX matches Win32 PROCESS_MEMORY_COUNTERS_EX.

func GetProcessMemoryInfo

func GetProcessMemoryInfo(h windows.Handle) (*PROCESS_MEMORY_COUNTERS_EX, error)

GetProcessMemoryInfo retrieves a process's memory counters.

type PdhCounter added in v0.2.0

type PdhCounter uintptr

PdhCounter is an opaque PDH counter handle.

func AddEnglishCounter added in v0.2.0

func AddEnglishCounter(query PdhQuery, path string) (PdhCounter, error)

AddEnglishCounter registers a wildcard or concrete counter path with a query.

type PdhQuery added in v0.2.0

type PdhQuery uintptr

PdhQuery is an opaque PDH query handle.

func OpenPdhQuery added in v0.2.0

func OpenPdhQuery() (PdhQuery, error)

OpenPdhQuery opens a PDH query for subsequent counter registration.

func (PdhQuery) Close added in v0.2.0

func (q PdhQuery) Close()

Close closes the underlying PDH query handle.

type SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION

type SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION struct {
	IdleTime   int64
	KernelTime int64
	UserTime   int64
	Reserved1  [2]int64
	Reserved2  uint32
}

SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION (NtQuerySystemInformation class 8).

func QueryProcessorPerformance

func QueryProcessorPerformance(numCPU int) ([]SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, error)

QueryProcessorPerformance returns per-logical-processor performance info.

type THREADENTRY32

type THREADENTRY32 struct {
	Size           uint32
	Usage          uint32
	ThreadID       uint32
	OwnerProcessID uint32
	BasePri        int32
	DeltaPri       int32
	Flags          uint32
}

THREADENTRY32 matches Win32 THREADENTRY32.

type WNDCLASSEXW

type WNDCLASSEXW struct {
	Size       uint32
	Style      uint32
	WndProc    uintptr
	ClsExtra   int32
	WndExtra   int32
	Instance   uintptr
	Icon       uintptr
	Cursor     uintptr
	Background uintptr
	MenuName   *uint16
	ClassName  *uint16
	IconSm     uintptr
}

WNDCLASSEXW struct used by RegisterClassExW.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL