npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

libwin32

v0.4.0

Published

Node bindings to native Win32 DLLs through Koffi

Downloads

11

Readme

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 64-bit platforms (Intel/AMD for now, ARM 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 and types you need. You may either import from libwin32 or from libwin32/<dllname> (without the .dll extension) if you know which dll a function belongs to. For example, import { MessageBox } from 'libwin32' and import { MessageBox } from 'libwin32/user32' would both work.
  3. (optional) Import some complementary constants. They greatly simplify calls to the Win32 API.
    • All constants are available via the libwin32/consts import.
    • Logically grouped constants 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.
  4. Call the functions as instructed by the Win32 API documentation. All functions, constants and types are named accordingly.
import { MessageBox } from 'libwin32'
import { MB_ } from 'libwin32/consts'

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.4.0

Many thanks to @shrirajh for the impressive work on b2bf65b!

  • user32.dll
    • AppendMenu
    • CheckMenuItem
    • CreatePopupMenu
    • DestroyMenu
    • GetCursorPos
    • SendMessage
    • SetForegroundWindow
    • TrackPopupMenu
  • shell32.dll
    • Shell_NotifyIcon

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:
    • Two Rollup plugins to ease the process of bundling this library with your own code and to boost its tree-shakeability. See rollup.demos.js for an example of usage.