|
1 | 1 | # libwin32 (work in progress)
|
2 | 2 | > Node bindings to native Win32 DLLs through [Koffi](https://koffi.dev).
|
3 | 3 |
|
| 4 | +````js |
| 5 | +import { MessageBox } from 'libwin32' |
| 6 | +import { MB_ } from 'libwin32/consts' |
| 7 | + |
| 8 | +const result = MessageBox( |
| 9 | + null, |
| 10 | + "Hello, world!", |
| 11 | + "libwin32", |
| 12 | + MB_.ICONINFORMATION | MB_.YESNO |
| 13 | +) |
| 14 | +```` |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
4 | 19 | ### In a nutshell:
|
5 | 20 | * Very simple and intuitive API (see [demos](./source//demos/)), with TypeScript definitions included.
|
6 | 21 | * Bundler friendly, designed with tree-shakeability in mind.
|
|
19 | 34 | * All constants are available via the `libwin32/consts` import.
|
20 | 35 | * Logically grouped constants are exported as `enum`s, where the prefix is the name of the enum. For instance, `WM_DESTROY` and `WM_KEYDOWN` are members of the `WM_` enum and can be accessed as `WM_.DESTROY` and `WM_.KEYDOWN`, respectively.
|
21 | 36 | 1. Call the functions as instructed by the [Win32 API documentation](https://learn.microsoft.com/en-us/windows/win32/api/).
|
22 |
| - * All functions, constants and types are named accordingly. |
23 |
| - * There are a few cases where it made sense to transform the C prototype to something more JS-friendly. For instance, in C, `GetWindowText` fills in a buffer whose address is passed as the second parameter to the function; in JS/TS, the function takes only one parameter and returns a string. |
| 37 | + * All functions, constants and types are named accordingly and the lib is fully typed so you may rely on code hints from your editor. |
| 38 | + * Many Win32 C structures have a size member (often named `cbSize`) that must be set before they are used as a parameter. For these, the lib provide a JS class that automatically sets that field when instantiated. See `WNDCLASSEX` for an example. |
| 39 | + * There are a few cases where it made sense to transform the C prototype to something more JS-friendly. For instance, in C, `GetWindowText()` fills in a buffer whose address is passed as the second parameter to the function; in JS/TS, the function takes only one parameter and returns a string. |
24 | 40 |
|
25 |
| -````js |
26 |
| -import { MessageBox } from 'libwin32' |
27 |
| -import { MB_ } from 'libwin32/consts' |
| 41 | +#### > Bundle the lib with your code |
| 42 | +The Win32 API has thousands of functions, structures and constants. While providing bindings for all of them is *not* a goal, the lib may eventually grow to something very, very big. |
28 | 43 |
|
29 |
| -const result = MessageBox( |
30 |
| - null, |
31 |
| - "Hello, world!", |
32 |
| - "libwin32", |
33 |
| - MB_.ICONINFORMATION | MB_.YESNO |
34 |
| -) |
35 |
| -```` |
| 44 | +To accommodate this, `libwin32` is "tree-shakeable by design". This feature relies on [Rollup's awesome tree-shaking capabilities](https://rollupjs.org/introduction/#tree-shaking). |
36 | 45 |
|
37 |
| - |
| 46 | +See [rollup.demos.js](../rollup.demos.js) to see how it's done, and build the demos (see below) to see the resulting code in the `/demos` directory. |
38 | 47 |
|
39 | 48 | #### > Build the lib
|
40 | 49 |
|
@@ -146,7 +155,7 @@ None.
|
146 | 155 | * `./source/demos`:
|
147 | 156 | * Some usage examples.
|
148 | 157 | * `./source/rollup`:
|
149 |
| - * Two [Rollup](https://rollup.org) plugins to ease the process of bundling this library with your own code and to boost its tree-shakeability. See [rollup.demos.js](./rollup.demos.js) to see how to use. |
| 158 | + * Two [Rollup](https://rollup.org) plugins to ease the process of bundling this library with your own code and to boost its tree-shakeability. See [rollup.demos.js](../rollup.demos.js) to see how to use. |
150 | 159 |
|
151 | 160 | ### Licence
|
152 | 161 | MIT.
|
0 commit comments