Socket
Socket
Sign inDemoInstall

libwin32

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libwin32

Node bindings to native Win32 DLLs through Koffi


Version published
Maintainers
0
Created
Source

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.
    • Not 100% tree-shakeable right now, but close. And working on it.
  • 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 W in 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
  1. Install the lib in your project: npm install libwin32
  2. Import the functions, constants and types you need. You may either import from libwin32 or from libwin32/<dllname> (without the .dll extension). Currently, only two dlls are available: kernel32 and user32.
  3. Call the functions as instructed by the Win32 API documentation. All functions, constants and types are named accordingly.
    • Constants like WM_DESTROY are exported as enums, where the prefix is the name of the enum. For instance, WM_DESTROY and WM_KEYDOWN are exported as WM.DESTROY and WM.KEYDOWN, respectively.
import { MessageBox, MB } from 'libwin32'

const result = MessageBox(
    null,
    "Hello, world!",
    "libwin32",
    MB.ICONINFORMATION | MB.YESNO
)
console.dir(result)

alt text

> Build the lib
$ git clone https://github.com/Septh/libwin32.git

$ cd libwin32

$ npm install

$ npm run build

The output goes to /dist.

> Run the demos

Build the lib, then:

  • Without bundling:
$ node dist/demos/messagebox.js

$ node dist/demos/enumdesktopwindows.js

$ node dist/demos/window.js
  • With bundling:
$ npm run build:demos

$ node demos/messagebox/messagebox.js

$ node demos/enumdesktopwindows/enumdesktopwindows.js

$ node demos/window/window.js

Changelog

See releases on Github.

Bindings so far

All functions come with their associated types and constants.

Added in 0.3.0
  • user32.dll
    • AdjustWindowRect
    • AdjustWindowRectEx
    • AnimateWindow
    • BringWindowToTop
    • BroadcastSystemMessage
    • BroadcastSystemMessageEx
    • CallWindowProc
    • EnumWindows
    • EnumDesktopWindows
    • FindWindow
    • FindWindowEx
    • GetAncestor
    • GetClassInfo
    • GetClassInfoEx
    • GetClassName
    • GetWindowText
Added in 0.2.0

None.

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.
  • ./source/rollup:
    • A Rollup plugin to ease the process of bundling this library and Koffi with your own code. See rollup.demo.js for an example of usage.

Keywords

FAQs

Package last updated on 18 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc