@bun-win32/wlanapi
v2.0.1
Published
Zero-dependency, zero-overhead Win32 WLANAPI bindings for Bun (FFI) on Windows.
Maintainers
Readme
@bun-win32/wlanapi
Zero-dependency, zero-overhead Win32 Wlanapi bindings for Bun on Windows.
Overview
@bun-win32/wlanapi exposes the wlanapi.dll exports using Bun's FFI. It provides a single class, Wlanapi, which lazily binds native symbols on first use. You can optionally preload a subset or all symbols up-front via Preload().
The bindings are strongly typed for a smooth DX in TypeScript.
Features
- Bun-first ergonomics on Windows 10/11.
- Direct FFI to
wlanapi.dll(Native Wifi, hosted network, and Wi-Fi Direct APIs). - In-source docs in
structs/Wlanapi.tswith links to Microsoft Learn. - Lazy binding on first call; optional eager preload (
Wlanapi.Preload()). - No wrapper overhead; calls map 1:1 to native APIs.
- Strongly-typed Win32 aliases, enums, and constants (see
types/Wlanapi.ts).
Requirements
- Bun runtime
- Windows 10 or later
Installation
bun add @bun-win32/wlanapiQuick Start
import { type Pointer, read, toArrayBuffer } from 'bun:ffi';
import Wlanapi, { WLAN_API_VERSION_2_0 } from '@bun-win32/wlanapi';
const negotiatedVersion = Buffer.alloc(4);
const clientHandle = Buffer.alloc(8);
const openStatus = Wlanapi.WlanOpenHandle(WLAN_API_VERSION_2_0, null, negotiatedVersion.ptr, clientHandle.ptr);
if (openStatus !== 0) {
throw new Error(`WlanOpenHandle failed with status ${openStatus}`);
}
const handle = clientHandle.readBigUInt64LE(0);
const interfaceList = Buffer.alloc(8);
try {
const enumStatus = Wlanapi.WlanEnumInterfaces(handle, null, interfaceList.ptr);
if (enumStatus !== 0) {
throw new Error(`WlanEnumInterfaces failed with status ${enumStatus}`);
}
const listPointer = read.ptr(interfaceList.ptr) as Pointer;
if (listPointer) {
const listHeader = new DataView(toArrayBuffer(listPointer, 0, 8));
const interfaceCount = listHeader.getUint32(0, true);
console.log(`Wireless interfaces: ${interfaceCount}`);
Wlanapi.WlanFreeMemory(listPointer);
}
} finally {
Wlanapi.WlanCloseHandle(handle, null);
}[!NOTE] AI agents: see
AI.mdfor the package binding contract and source-navigation guidance. It explains how to use the package without scanning the entire implementation.
Examples
Run the included example:
bun run exampleNotes
- Either rely on lazy binding or call
Wlanapi.Preload(). - Windows only. Bun runtime required.
- SAL types & naming: nullability is in the type —
Optional<T>(formally optional, SAL_*opt_) andNullable<T>(plain[in]/[out]the docs say can be NULL), the null sentinel derived fromT(nullfor pointersLP*/P*,0nfor handles/by-value addresses); direction is in the parameter name —_out(_Out_),_in_out(_Inout_),_In_bare. SeeAI.mdand the repoAGENTS.md.
