Windows Package v0.1.0

Source
Unstable API
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.dll link 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.

Raw bindings
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

FunctionDescription
AllocConsoleAllocate a console for the process.
GetStdHandleGet a standard device handle.
ReadConsoleARead characters from the console.
WriteConsoleAWrite a narrow string to the console.
WriteConsoleWWrite a UTF-16 string to the console.
BeepSound a tone on the speaker.

File I/O

FunctionDescription
CreateFileACreate or open a file or device.
ReadFileRead bytes from a file or device.
WriteFileWrite bytes to a file or device.
GetFileSizeExGet the size of a file.
SetFilePointerExMove the file pointer.

Filesystem

FunctionDescription
CopyFileACopy a file.
MoveFileAMove a file or directory.
DeleteFileADelete a file.
CreateDirectoryACreate a directory.
RemoveDirectoryARemove an empty directory.
GetFileAttributesARead a file's attributes.
SetFileAttributesASet a file's attributes.
GetCurrentDirectoryARead the current directory.
SetCurrentDirectoryAChange the current directory.

File enumeration

FunctionDescription
FindFirstFileABegin a directory search.
FindNextFileAContinue a directory search.
FindCloseClose a search handle.

Heap and memory

FunctionDescription
GetProcessHeapGet the process's default heap.
HeapAllocAllocate a heap block.
HeapReAllocResize a heap block.
HeapFreeFree a heap block.
RtlCopyMemoryCopy bytes between blocks.
RtlFillMemoryFill a block with a byte.
RtlZeroMemoryZero a block.
RtlCompareMemoryCompare two blocks.

Process and thread

FunctionDescription
ExitProcessTerminate the process.
SleepSuspend the current thread.
GetCurrentProcessIdGet the process ID.
GetCurrentThreadIdGet the thread ID.

Time

FunctionDescription
GetTickCount64Milliseconds since system start.
GetLocalTimeCurrent local date and time.
GetSystemTimeCurrent UTC date and time.

Text conversion

FunctionDescription
MultiByteToWideCharConvert a narrow string to UTF-16.
WideCharToMultiByteConvert UTF-16 to another code page.

Dynamic libraries

FunctionDescription
LoadLibraryALoad a DLL.
FreeLibraryUnload a DLL.
GetProcAddressResolve an exported symbol.

Handles and errors

FunctionDescription
CloseHandleClose an object handle.
GetLastErrorRead 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;
}