Skip to content

Commit 0242c1c

Browse files
committed
Hotfixed Testing
1 parent dfb70a5 commit 0242c1c

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

source/demos/new-calls.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
import { CloseHandle, OpenProcess, QueryFullProcessImageName } from "../win32/kernel32.js"
3+
import { GetClassName, GetForegroundWindow, GetWindowText, GetWindowThreadProcessId, MessageBox } from "../win32/user32.js"
4+
5+
const windowHref = GetForegroundWindow()
6+
const processId = GetWindowThreadProcessId(windowHref)
7+
const windowText = GetWindowText(windowHref)
8+
9+
const PROCESS_QUERY_INFORMATION = 0x0400
10+
const PROCESS_VM_READ = 0x0010
11+
const openProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, processId)
12+
const className = GetClassName(windowHref)
13+
14+
let executable
15+
16+
MessageBox(null, 'Testing2', "libwin32", 0)
17+
if(openProcess){
18+
MessageBox(null, 'Testing', "libwin32", 0)
19+
executable = QueryFullProcessImageName(openProcess, 0)
20+
CloseHandle(openProcess)
21+
}
22+
23+
24+
25+
MessageBox(
26+
null,
27+
`processId: ${processId}\n
28+
windowText: ${windowText}\n
29+
executable: ${executable}\n
30+
className: ${className}\n`,
31+
"libwin32",0
32+
)
33+
34+

source/win32/kernel32/process.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ import { kernel32 } from './_lib.js'
1414
*
1515
* https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocess
1616
*/
17-
export const OpenProcess:koffi.KoffiFunc<(
17+
/*@__NO_SIDE_EFFECTS__*/
18+
export function OpenProcess(
1819
dwDesiredAccess: number,
1920
bInheritHandle: boolean,
2021
dwProcessId: number
21-
) => HANDLE<string>> = kernel32('OpenProcess', cHANDLE, [ cDWORD, cBOOL, cDWORD ])
22+
): string | null {
23+
const flag = bInheritHandle ? 1 : 0
24+
return _OpenProcess(dwDesiredAccess, flag, dwProcessId)
25+
}
26+
const _OpenProcess = kernel32('OpenProcess', cHANDLE, [ cDWORD, cBOOL, cDWORD ])
2227

2328
/**
2429
* Get full Image Name of Process (A)
@@ -27,7 +32,7 @@ export const OpenProcess:koffi.KoffiFunc<(
2732
*/
2833
/*@__NO_SIDE_EFFECTS__*/
2934
export function QueryFullProcessImageNameA(
30-
hProcess: HANDLE<''>,
35+
hProcess: string,
3136
dwFlags: number
3237
): string | null {
3338
const exeName = new Uint16Array(256)
@@ -46,7 +51,7 @@ const _QueryFullProcessImageNameA = kernel32('QueryFullProcessImageNameW', cBOOL
4651
*/
4752
/*@__NO_SIDE_EFFECTS__*/
4853
export function QueryFullProcessImageName(
49-
hProcess: HANDLE<string>,
54+
hProcess: string,
5055
dwFlags: number
5156
): string | null {
5257
const exeName = new Uint16Array(256)
@@ -65,7 +70,7 @@ const _QueryFullProcessImageName = kernel32('QueryFullProcessImageNameW', cBOOL,
6570
*
6671
*/
6772
export const CloseHandle:koffi.KoffiFunc<(
68-
hObject: HANDLE<string>
73+
hObject: string
6974
) => boolean> = kernel32('CloseHandle', cBOOL, [ cHANDLE ])
7075

71-
// #endregion
76+
// #endregion

0 commit comments

Comments
 (0)