win32-def
TypeScript icon, indicating that this package has built-in type declarations

26.1.2 • Public • Published

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

Package Version
win32-api main-svg
win32-def def-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> {
  ClientToScreen: (hWnd: T.HWND, lpPoint: S.POINT_Type) => 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

Package Sidebar

Install

npm i win32-def

Weekly Downloads

408

Version

26.1.2

License

MIT

Unpacked Size

912 kB

Total Files

425

Last publish

Collaborators

  • waiting