win32-api
Definitions of Windows Date Types for koffi
Compile successfully with
- Node.js v18
- Node.js v20
- Node.js v22
Packages
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: 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