mirror of
https://github.com/Septh/libwin32
synced 2026-08-09 12:19:58 +00:00
v0.2.0
…
…
libwin32 (work in progress)
Node bindings to native Win32 DLLs through Koffi.
In a nutshell:
- Very simple and intuitive API (see demos), with TypeScript definitions included.
- Bundler friendly, designed with tree-shakeability in mind.
- Opinionated:
- Only targets x64 platforms (ARM-64 may be added later, no warranty though).
- Only exposes Unicode functions and data structures (those whose name ends in
Win the Win32 API).
- Very easy to extend with additional functions, data structures and constants. I will add some myself time permitting; any help would be mucho appreciated.
How to...
> Use the lib in your code
- Install the lib in your project:
npm install libwin32 - Import the functions, constants and types you need. You may either import from
libwin32or fromlibwin32/<dllname>(without the.dllextension). Currently, only two dlls are available:kernel32anduser32. - Call the functions as instructed by the Win32 API documentation. All functions, constants and types are named accordingly.
- Constants like
WM_DESTROYare exported asconst enums, where the prefix is the name of the enum. For instance,WM_DESTROYandWM_KEYDOWNare exported asWM.DESTROYandWM_KEYDOWN, respectively.
- Constants like
import { MessageBox, MB } from 'libwin32'
const result = MessageBox(
null,
"Hello, world!",
"libwin32",
MB.ICONINFORMATION | MB.YESNO
)
console.dir(result)
> Build the lib
$ git clone https://github.com/Septh/libwin32.git
$ cd libwin32
$ npm install
$ npm run build
The output goes to /dist for the library, and /demos for the demos.
> See the demos
Build the lib, then:
- Without bundling:
$ node dist/demos/window.js
$ node dist/demos/messagebox.js
- With bundling:
$ npm run build:demos
$ node demos/window/window.js
$ node demos/messagebox/messagebox.js
Changelog
See releases on Github.
Bindings so far
All functions come with their associated types and constants.
Since 0.1.0
- kernel32.dll
- GetLastError
- GetModuleHandle
- user32.dll
- CreateWindow
- CreateWindowEx
- DefWindowProc
- DestroyCursor
- DestroyIcon
- DispatchMessage
- GetMessage
- LoadCursor
- LoadIcon
- LoadImage
- MessageBox
- PostQuitMessage
- RegisterClass
- RegisterClassEx
- ShowWindow
- ShowWindowAsync
- TranslateMessageEx
- UnregisterClass
- UpdateWindow
Repository structure
./source/win32:- The main bindings source files.
./source/demos:- Some usage examples. (only two at the time, more to come later)
./source/rollup:- A Rollup plugin to ease the process of bundling this library with your code. See rollup.demo.js for an example of usage.
./source/stubs:- Used for efficient bundling of Koffi with
Rollup.
- Used for efficient bundling of Koffi with
Languages
TypeScript
99.1%
JavaScript
0.9%
