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

20.4.1 • Public • Published

win32-api

Definitions of Windows Date Types for node-ffi, node-ffi-napi

GitHub tag License Available platform ci Build status codecov Conventional Commits lerna

Initialization

npm run repo:init

Packages

Package Version
win32-api main-svg
win32-def def-svg

What can I do with this?

Write node-ffi or node-ffi-napi calling win32 native functions code by Typescript with Types support.

Installing

npm install win32-def

Usage

FFI

import * as ffi from 'ffi-napi'
import { DModel as M, DTypes as W, FModel as FM } from 'win32-def'

export interface Win32Fns extends FM.DllFuncsModel {
  ClientToScreen(hWnd: M.HWND, lpPoint: M.LPPOINT): M.BOOL
  GetAncestor(hwnd: M.HWND, gaFlags: M.UINT): M.HWND
}

export const user32: Win32Fns = ffi.Library('user32.dll', {
  ClientToScreen: [W.BOOL, [W.HWND, W.LPPOINT] ],
  GetAncestor: [W.HWND, [W.HWND, W.UINT] ],
})
import * as ffi from 'ffi-napi'
import { DModel as M, DTypes as W, FModel as FM } from 'win32-def'

export interface Win32Fns extends FM.DllFuncsModel {
  ClientToScreen(hWnd: M.HWND, lpPoint: M.LPPOINT): M.BOOL
  GetAncestor(hwnd: M.HWND, gaFlags: M.UINT): M.HWND
}

export const user32: FM.ExpandFnModel<Win32Fns> = ffi.Library('user32.dll', {
  ClientToScreen: [W.BOOL, [W.HWND, W.LPPOINT] ],
  GetAncestor: [W.HWND, [W.HWND, W.UINT] ],
})

// You can calling with BOTH sync and async method
const hWnd = user32.GetAncestor(hWnd, uint)
user32.GetAncestor.async(handle, uint, (err, hWnd) => {
  // typeof hWnd will be the same of ReturnType of sync method
  if (err) {
    throw err
  }
  if (hWnd && !ref.isNull(hWnd) && ref.address(hWnd)) {
    // ...
  }
  else {
    throw new Error('hWnd invalid')
  }
})

Relevant

License

MIT

Languages

Package Sidebar

Install

npm i win32-def

Weekly Downloads

199

Version

20.4.1

License

MIT

Unpacked Size

491 kB

Total Files

199

Last publish

Collaborators

  • waiting