Windows Package v0.1.0
The package is under active development and its API is not yet stable. Names, signatures, and behavior may change between releases, and this documentation will be updated to match.
Direct Win32 API bindings for Rux programs.
Package: Windows
Source: github.com/rux-lang/Rux/tree/main/Packages/Windows
The package imports a focused set of functions from kernel32.dll, covering console and file I/O, heap and memory operations, processes, time, filesystem operations, text conversion, directory enumeration, and dynamic libraries.
Requirements
- Windows
- A Rux compiler with the
kernel32.dlllink support
The functions are declared in a #Link("Kernel32.dll") extern { ... } block, so they resolve at link time against the system DLL. These bindings mirror Win32 closely and are not portable — reach for the cross-platform packages (Io, Memory) when they provide the operation you need.
Installation
rux add Windows
rux install
Then import the symbols you need:
import Windows::{ GetLastError, GetTickCount64 };
Calling Conventions
Most fallible functions return bool32: nonzero means success and zero means failure. Call GetLastError immediately after a failure when the function's contract defines a last-error value. Pointer-returning functions use null as their failure sentinel unless a page states otherwise.
Functions ending in A take narrow, null-terminated strings interpreted by the Windows ANSI API; they are not inherently UTF-8. Functions ending in W take UTF-16 char16 data. Buffer lengths are measured in bytes or characters as each function states.
These APIs do not automatically close handles, free heap blocks, retry partial I/O, validate pointers, or preserve
GetLastError. The caller owns those responsibilities.Functions
Console
| Function | Description |
|---|---|
AllocConsole | Allocate a console for the process. |
GetStdHandle | Get a standard device handle. |
ReadConsoleA | Read characters from the console. |
WriteConsoleA | Write a narrow string to the console. |
WriteConsoleW | Write a UTF-16 string to the console. |
Beep | Sound a tone on the speaker. |
File I/O
| Function | Description |
|---|---|
CreateFileA | Create or open a file or device. |
ReadFile | Read bytes from a file or device. |
WriteFile | Write bytes to a file or device. |
GetFileSizeEx | Get the size of a file. |
SetFilePointerEx | Move the file pointer. |
Filesystem
| Function | Description |
|---|---|
CopyFileA | Copy a file. |
MoveFileA | Move a file or directory. |
DeleteFileA | Delete a file. |
CreateDirectoryA | Create a directory. |
RemoveDirectoryA | Remove an empty directory. |
GetFileAttributesA | Read a file's attributes. |
SetFileAttributesA | Set a file's attributes. |
GetCurrentDirectoryA | Read the current directory. |
SetCurrentDirectoryA | Change the current directory. |
File enumeration
| Function | Description |
|---|---|
FindFirstFileA | Begin a directory search. |
FindNextFileA | Continue a directory search. |
FindClose | Close a search handle. |
Heap and memory
| Function | Description |
|---|---|
GetProcessHeap | Get the process's default heap. |
HeapAlloc | Allocate a heap block. |
HeapReAlloc | Resize a heap block. |
HeapFree | Free a heap block. |
RtlCopyMemory | Copy bytes between blocks. |
RtlFillMemory | Fill a block with a byte. |
RtlZeroMemory | Zero a block. |
RtlCompareMemory | Compare two blocks. |
Process and thread
| Function | Description |
|---|---|
ExitProcess | Terminate the process. |
Sleep | Suspend the current thread. |
GetCurrentProcessId | Get the process ID. |
GetCurrentThreadId | Get the thread ID. |
Time
| Function | Description |
|---|---|
GetTickCount64 | Milliseconds since system start. |
GetLocalTime | Current local date and time. |
GetSystemTime | Current UTC date and time. |
Text conversion
| Function | Description |
|---|---|
MultiByteToWideChar | Convert a narrow string to UTF-16. |
WideCharToMultiByte | Convert UTF-16 to another code page. |
Dynamic libraries
| Function | Description |
|---|---|
LoadLibraryA | Load a DLL. |
FreeLibrary | Unload a DLL. |
GetProcAddress | Resolve an exported symbol. |
Handles and errors
| Function | Description |
|---|---|
CloseHandle | Close an object handle. |
GetLastError | Read the last-error code. |
Types and constants
The standard handle constants, the CodePage and CreationDisposition enums, and the FileTime, SystemTime, and Win32FindDataA structures are listed on the types and constants page.
Example
import Windows::{ GetStdHandle, StdOutputHandle, WriteFile };
func Main() -> int {
let output = GetStdHandle(StdOutputHandle);
let text = "Hello, Windows!\n";
var written: uint32 = 0;
let ok = WriteFile(output, text.data, text.length as uint32, @written, null);
return ok != 0 && written == text.length as uint32 ? 0 : 1;
}