https://github.com/djdeveloperr/deno_win32
Fast and complete Win32 API bindings for Deno using FFI
https://github.com/djdeveloperr/deno_win32
bindings deno ffi hacktoberfest win32 windows
Last synced: 8 months ago
JSON representation
Fast and complete Win32 API bindings for Deno using FFI
- Host: GitHub
- URL: https://github.com/djdeveloperr/deno_win32
- Owner: DjDeveloperr
- License: apache-2.0
- Created: 2022-10-02T13:05:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-03T04:37:38.000Z (over 2 years ago)
- Last Synced: 2025-02-25T08:01:39.389Z (10 months ago)
- Topics: bindings, deno, ffi, hacktoberfest, win32, windows
- Language: TypeScript
- Homepage:
- Size: 18.5 MB
- Stars: 48
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deno Win32
[](https://github.com/DjDeveloperr/deno_win32/releases)
[](https://github.com/DjDeveloperr/deno_win32/actions/workflows/ci.yml)
[](https://github.com/DjDeveloperr/deno_win32/blob/master/LICENSE)
[](https://github.com/sponsors/DjDeveloperr)
Fast and complete Win32 API bindings for Deno using FFI.
## Example
```ts
import {
MB_OKCANCEL,
MessageBoxA,
} from "https://win32.deno.dev/0.4.1/UI.WindowsAndMessaging";
const result = MessageBoxA(
null,
"Hello, world!",
"Hello",
MB_OKCANCEL,
); // 1 (OK) or 2 (Cancel)
```
More in `examples/` such as demonstrating OpenGL API usage.
## Usage
You need to pass `--allow-ffi` and `--unstable` flags in order to access the
Win32 API.
```sh
deno run --allow-ffi --unstable
```
Note: It is highly recommended to import only APIs you need. Do not import from
`mod.ts` as it will import all sub modules which you might not even need. WinAPI
is huge, so are the bindings.
## Documentation
It is recommened to read the official documentation of
[Win32 API](https://learn.microsoft.com/en-us/windows/win32/api/).
APIs almost map 1:1 with the official ones, just certain types have to be
transformed to be sent into C-land like `string` is first converted into
null-terminated string depending on the argument (PSTR or PWSTR).
Constants are exported as-is. Structs are defined as interfaces with
corresponding JS types in fields. We also export a helper function
`alloc${STRUCT}` which accepts `Partial<${STRUCT}>` to create a new struct and
return its buffer as `Uint8Array`. A constant called `sizeof${camelCasedStruct}`
is exported which is the size of the struct in bytes.
Some APIs have been (manually) marked as Async capable which adds a
`${name}Async` variant of the function along with original one which runs on a
different thread natively and returns a promise. If you want any other API to be
Async capable, please open an issue or a PR. Note that Async calls cannot go
through v8 fastapi path, so they have more overhead than normal ones.
## Contributing
Code is formatted using `deno fmt` and linted using `deno lint`. Please make
sure to run these commands before committing.
## License
Apache-2.0. Check [LICENSE](LICENSE) for more details.
Copyright 2022-2023 © DjDeveloperr