Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

win32-def

Package Overview
Dependencies
Maintainers
0
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

win32-def

win32 definitions for node-ffi

  • 22.7.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
444
decreased by-60.5%
Maintainers
0
Weekly downloads
 
Created
Source

win32-api

Definitions of Windows Date Types for koffi

GitHub tag License Available platform ci codecov Conventional Commits lerna

Significant Changes.V22

Compile successfully with

  • Node.js v18
  • Node.js v20
  • Node.js v22

Packages

PackageVersion
win32-apimain-svg
win32-defdef-svg

What can I do with this?

Write koffi calling win32 native functions code by Typescript with Types support.

Installing

npm install win32-def

Usage

FFI Def

import * as D from 'win32-def/def'
import * as S from 'win32-def/struct'
import * as T from 'win32-def/types'

export class DefWin32 extends Def_B implements T.LibDefBase {
  [x: string]: T.FnDefFullParams
  static ClientToScreen = [D.BOOL, [D.HWND, `_Inout_ ${S.LPPOINT}`]]
  static EnumDisplayDevicesW = [D.BOOL, [D.LPCWSTR, D.DWORD, `_Inout_ ${S.LPDISPLAY_DEVICEW}`, D.DWORD]]
  static FindWindowExW = [D.HWND, [D.HWND, D.HWND, D.LPCTSTR, D.LPCTSTR]]
  static GetCursorPos = [D.BOOL, [`_Out_ ${S.LPPOINT}`]]
}

export class Win32 implements T.LibDef2Type<typeof DefWin32> {
  // test fake struct LPPOINT
  ClientToScreen: (hWnd: T.HWND, lpPoint: T.LPPOINT) => T.BOOL

  EnumDisplayDevicesW: (
    lpDevice: T.LPCWSTR | null,
    iDevNum: T.DWORD,
    lpDisplayDevice: S.DISPLAY_DEVICEW_Type,
    dwFlags: T.DWORD,
  ) => T.BOOL

  FindWindowExW: (
    hwndParent: T.HWND,
    hwndChildAfter: T.HWND,
    lpszClass: T.LPCTSTR | null,
    lpszWindow: T.LPCTSTR | null,
  ) => T.HWND

  GetCursorPos: (lpPoint: S.POINT_Type) => T.BOOL
}

Calling

import { load } from 'win32-def'
import { POINT_Factory } from 'win32-def/struct'

const lib = load<Win32>(options)
const { payload: pos } = POINT_Factory()

const res = await lib.GetCursorPos_Async(pos)
assert(res > 0)
console.info({ res, pos })
assert(pos.x >= 0 && pos.y >= 0) 

Relevant

License

MIT

Languages

Keywords

FAQs

Package last updated on 30 Jun 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