Skip to content

Commit dfb70a5

Browse files
committed
Push with new code and some Bundling fixes
1 parent e2b9084 commit dfb70a5

File tree

8 files changed

+4687
-517
lines changed

8 files changed

+4687
-517
lines changed

package-lock.json

+4,524-497
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+20-14
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"koffi",
1212
"x64"
1313
],
14+
"main": "./dist/index.js",
15+
"types": "./dist/index.d.ts",
1416
"homepage": "https://github.com/Septh/libwin32#readme",
1517
"repository": {
1618
"type": "git",
@@ -47,7 +49,7 @@
4749
"#consts-base": "./source/win32/consts"
4850
},
4951
"engines": {
50-
"node": ">= 18.19.0 || >= 20.6.0"
52+
"node": ">= 18.19.0 || >= 20.6.0 || >= 22.14.0"
5153
},
5254
"engineStrict": true,
5355
"files": [
@@ -60,23 +62,27 @@
6062
"build:demos": "rollup -c rollup.demos.js",
6163
"clean": "rimraf dist demos",
6264
"test": "echo No test yet",
65+
"check-packages": "npx npm-check -u -E",
66+
"refresh-packages": "rm -rf node_modules && rm -rf package-lock.json && npm i",
6367
"prepublishOnly": "npm run clean && npm run build && npm run build:demos"
6468
},
6569
"dependencies": {
66-
"koffi": "^2.9.0"
70+
"koffi": "2.10.1"
6771
},
6872
"devDependencies": {
69-
"@rollup/plugin-commonjs": "^28.0.1",
70-
"@rollup/plugin-node-resolve": "^15.2.3",
71-
"@rollup/plugin-typescript": "^12.1.1",
72-
"@types/node": "^22.5.1",
73-
"magic-string": "^0.30.11",
74-
"regex": "^5.0.2",
75-
"rimraf": "^6.0.1",
76-
"rollup": "^4.21.2",
77-
"rollup-plugin-code-raker": "^1.0.0",
78-
"rollup-plugin-node-externals": "^7.1.3",
79-
"tslib": "^2.7.0",
80-
"typescript": "^5.5.4"
73+
"@rollup/plugin-commonjs": "28.0.3",
74+
"@rollup/plugin-node-resolve": "16.0.1",
75+
"@rollup/plugin-typescript": "12.1.2",
76+
"@types/node": "22.13.14",
77+
"magic-string": "0.30.17",
78+
"npm-check": "6.0.1",
79+
"regex": "6.0.1",
80+
"rimraf": "6.0.1",
81+
"rollup": "4.38.0",
82+
"rollup-plugin-code-raker": "1.0.1",
83+
"rollup-plugin-node-externals": "8.0.0",
84+
"tslib": "2.7.0",
85+
"typescript": "5.8.2"
86+
8187
}
8288
}

source/win32/kernel32.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export { kernel32 } from './kernel32/_lib.js'
22
export * from './kernel32/console.js'
33
export * from './kernel32/module.js'
44
export * from './kernel32/error.js'
5+
export * from './kernel32/process.js'

source/win32/kernel32/process.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { inout, koffi, out, textDecoder } from '../../private.js'
2+
import { cBOOL, cDWORD, cHANDLE, cLPDWORD, cLPWSTR, HANDLE } from '../../ctypes.js'
3+
import { kernel32 } from './_lib.js'
4+
5+
// #region Types
6+
7+
8+
// #endregion
9+
10+
// #region Functions
11+
12+
/**
13+
* Opens a process and returns a handle to it.
14+
*
15+
* https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess
16+
*/
17+
export const OpenProcess:koffi.KoffiFunc<(
18+
dwDesiredAccess: number,
19+
bInheritHandle: boolean,
20+
dwProcessId: number
21+
) => HANDLE<string>> = kernel32('OpenProcess', cHANDLE, [ cDWORD, cBOOL, cDWORD ])
22+
23+
/**
24+
* Get full Image Name of Process (A)
25+
*
26+
* https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamea
27+
*/
28+
/*@__NO_SIDE_EFFECTS__*/
29+
export function QueryFullProcessImageNameA(
30+
hProcess: HANDLE<''>,
31+
dwFlags: number
32+
): string | null {
33+
const exeName = new Uint16Array(256)
34+
const dwSize = [ exeName.length ] as [ number ]
35+
return _QueryFullProcessImageNameA(hProcess, dwFlags, exeName, dwSize) === 0
36+
? null
37+
: textDecoder.decode(exeName).slice(0, dwSize[0])
38+
}
39+
const _QueryFullProcessImageNameA = kernel32('QueryFullProcessImageNameW', cBOOL, [ cHANDLE, cDWORD, out(cLPWSTR), inout(cLPDWORD) ])
40+
41+
/**
42+
* Get full Image Name of Process
43+
*
44+
*
45+
* https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-queryfullprocessimagenamew
46+
*/
47+
/*@__NO_SIDE_EFFECTS__*/
48+
export function QueryFullProcessImageName(
49+
hProcess: HANDLE<string>,
50+
dwFlags: number
51+
): string | null {
52+
const exeName = new Uint16Array(256)
53+
const dwSize = [ exeName.length ] as [ number ]
54+
return _QueryFullProcessImageName(hProcess, dwFlags, exeName, dwSize) === 0
55+
? null
56+
: textDecoder.decode(exeName).slice(0, dwSize[0])
57+
}
58+
const _QueryFullProcessImageName = kernel32('QueryFullProcessImageNameW', cBOOL, [ cHANDLE, cDWORD, out(cLPWSTR), inout(cLPDWORD) ])
59+
60+
/**
61+
*
62+
* Close handle to process
63+
*
64+
* https://learn.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-closehandle
65+
*
66+
*/
67+
export const CloseHandle:koffi.KoffiFunc<(
68+
hObject: HANDLE<string>
69+
) => boolean> = kernel32('CloseHandle', cBOOL, [ cHANDLE ])
70+
71+
// #endregion

source/win32/user32/class.ts

+13
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ export function GetClassName(hWnd: HWND): string {
159159
}
160160
const _GetClassName = user32('GetClassNameW', cINT, [ cHWND, out(cLPWSTR), cINT ])
161161

162+
/**
163+
* Retrieves the name of the class to which the specified window belongs (with ClassName A).
164+
*
165+
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getclassnamea
166+
*/
167+
/*@__NO_SIDE_EFFECTS__*/
168+
export function GetClassNameA(hWnd: HWND): string {
169+
const out = new Uint16Array(512)
170+
const len = _GetClassNameA(hWnd, out, 512)
171+
return textDecoder.decode(out).slice(0, len)
172+
}
173+
const _GetClassNameA = user32('GetClassNameA', cINT, [ cHWND, out(cLPWSTR), cINT ])
174+
162175
/**
163176
* Registers a window class for subsequent use in calls to the CreateWindowEx function.
164177
*

source/win32/user32/window.ts

+47-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import {
66
import {
77
cLPVOID, cBOOL, cINT, cUINT, cDWORD, cLPWSTR, cLPCWSTR,
88
cHINSTANCE, cWPARAM, cLPARAM, cLRESULT,
9-
type HINSTANCE, type HANDLE, type LPARAM, type WPARAM, type LRESULT
9+
type HINSTANCE, type HANDLE, type LPARAM, type WPARAM, type LRESULT,
10+
cLPDWORD
1011
} from '../../ctypes.js'
1112
import { user32 } from './_lib.js'
1213
import { cHMENU, type HMENU } from './menu.js'
1314
import { cLPRECT, type RECT } from './rect.js'
14-
import type { HWND_ } from '../consts/HWND.js'
15+
import { HWND_ } from '../consts/HWND.js'
1516
import type { WS_, WS_EX_ } from '../consts/WS.js'
1617
import type { WM_ } from '../consts/WM.js'
1718
import type { GA_ } from '../consts/GA.js'
@@ -233,3 +234,47 @@ export const UpdateWindow: koffi.KoffiFunc<(
233234
export const SetForegroundWindow: koffi.KoffiFunc<(
234235
hWnd: HWND
235236
) => number> = user32('SetForegroundWindow', cBOOL, [ cHWND ])
237+
238+
/**
239+
*
240+
* Gets the current foreground window (the window with which the user is currently working).
241+
*
242+
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow
243+
*
244+
*/
245+
export const GetForegroundWindow: koffi.KoffiFunc<() => HWND> = user32('GetForegroundWindow', cHWND, [])
246+
247+
/**
248+
*
249+
* Get Window's Thread Process ID
250+
*
251+
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowthreadprocessid
252+
*
253+
*/
254+
/*@__NO_SIDE_EFFECTS__*/
255+
export function GetWindowThreadProcessId(hWnd: HWND): number {
256+
const out = [ 0 ] as [ number ]
257+
_GetWindowThreadProcessId(hWnd, out)
258+
return out[0]
259+
}
260+
const _GetWindowThreadProcessId: koffi.KoffiFunc<(
261+
hWnd: HWND,
262+
lpdwProcessId: [ number ]
263+
) => number> = user32('GetWindowThreadProcessId', cDWORD, [cHWND, inout(cLPDWORD)])
264+
265+
/**
266+
*
267+
* Get Window's Text A
268+
*
269+
* https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowtexta
270+
*
271+
*/
272+
/*@__NO_SIDE_EFFECTS__*/
273+
export function GetWindowTextA(hWnd: HWND): string {
274+
const out = new Uint16Array(512)
275+
const len = _GetWindowTextA(hWnd, out, 512)
276+
return textDecoder.decode(out).slice(0, len)
277+
}
278+
const _GetWindowTextA = user32('GetWindowTextA', cINT, [ cHWND, out(cLPWSTR), cINT ])
279+
280+

tsconfig.demos.json

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
"extends": "./tsconfig.build.json",
33
"include": [ "./source/demos" ],
44
"compilerOptions": {
5+
6+
//Included due to current issue with rollup typescript plugin (https://github.com/rollup/plugins/issues/1583)
7+
"module": "nodenext",
8+
"moduleResolution": "nodenext",
9+
510
"sourceMap": false,
611
"declaration": false,
712
"declarationMap": false,

tsconfig.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
"noEmit": true,
1010

1111
// Module
12-
"module": "Node16",
12+
"module": "nodenext",
1313
"esModuleInterop": true,
1414
"allowSyntheticDefaultImports": true,
15+
"moduleResolution": "nodenext",
1516

1617
// Libs
17-
"target": "ES2023",
18-
"lib": [ "ES2023" ],
18+
"target": "ESNext",
19+
"lib": [ "ESNext" ],
1920
"skipLibCheck": true,
2021
"skipDefaultLibCheck": true,
2122

@@ -30,6 +31,7 @@
3031
"noUnusedParameters": false,
3132
"noFallthroughCasesInSwitch": false,
3233
"forceConsistentCasingInFileNames": true,
33-
// "isolatedModules": true,
34+
"isolatedModules": true,
35+
// "allowImportingTsExtensions": true
3436
}
3537
}

0 commit comments

Comments
 (0)