System libraries
Windows
kernel32, advapi32, and user32.
Windows modules use portable core types only. Wide-string and COM-heavy APIs are held back until UnFFI has a cross-runtime ownership and UTF-16 story.
kernel32
GetTickCount64() is kernel uptime in milliseconds, not Date.now() or performance.now().
import { openKernel32 } from 'unffi/windows/kernel32'
if (process.platform !== 'win32') process.exit(0)
await using kernel32 = await openKernel32()
console.log({
processId: kernel32.symbols.GetCurrentProcessId(),
threadId: kernel32.symbols.GetCurrentThreadId(),
uptimeMs: kernel32.symbols.GetTickCount64(),
nativeStringLength: kernel32.symbols.lstrlenA('native-unffi'),
})advapi32
GetUserNameA demonstrates a common Win32 pattern: allocate an output buffer and pass its length by reference.
import { openAdvapi32 } from 'unffi/windows/advapi32'
if (process.platform !== 'win32') process.exit(0)
await using advapi32 = await openAdvapi32()
const name = new Uint8Array(257)
const size = new Uint32Array([name.byteLength])
const ok = advapi32.symbols.GetUserNameA(name, size)
if (ok === 0) throw new Error('GetUserNameA failed')
const username = new TextDecoder().decode(
name.subarray(0, Math.max(0, (size[0] ?? 1) - 1)),
)This uses the ANSI A variant. Keep inputs ASCII unless the binding explicitly documents a wide-string API.
user32
user32 exposes desktop metrics and settings that do not have a direct JavaScript equivalent.
import { openUser32 } from 'unffi/windows/user32'
if (process.platform !== 'win32') process.exit(0)
const SM_CXSCREEN = 0
const SM_CYSCREEN = 1
await using user32 = await openUser32()
console.log({
screenWidth: user32.symbols.GetSystemMetrics(SM_CXSCREEN),
screenHeight: user32.symbols.GetSystemMetrics(SM_CYSCREEN),
doubleClickTimeMs: user32.symbols.GetDoubleClickTime(),
})Headless Windows runners may report different display metrics than a desktop session.