1 /**
2     Win32 Implementation for nulib.threading.internal.process
3 
4     Copyright:
5         Copyright © 2025, Kitsunebi Games
6         Copyright © 2025, Inochi2D Project
7     
8     License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9     Authors:   Luna Nielsen
10 */
11 module nulib.win32.threading.process;
12 import nulib.threading.internal.process;
13 import numem;
14 
15 class Win32Process : NativeProcess {
16 private:
17 @nogc:
18     void* handle_;
19 
20 public:
21 
22     /**
23         The ID of the process.
24     */
25     override @property uint pid() @safe => GetProcessId(handle_);
26 
27     /**
28         Constructs a new Win32Process.
29     */
30     this(void* handle) nothrow {
31         this.handle_ = handle;
32     }
33 
34     /**
35         Kills the given process.
36 
37         Returns:
38             $(D true) if the operation succeeded,
39             $(D false) otherwise.
40     */
41     override
42     bool kill() @safe {
43         return TerminateProcess(handle_, 0);
44     }
45 }
46 
47 extern(C) export
48 NativeProcess _nu_process_get_self() @nogc @trusted nothrow {
49     return nogc_new!Win32Process(GetCurrentProcess());
50 }
51 
52 //
53 //          BINDINGS
54 //
55 extern(Windows):
56 extern void* GetCurrentProcess() @trusted @nogc nothrow;
57 extern uint GetProcessId(void*) @trusted @nogc nothrow;
58 extern bool TerminateProcess(void*, uint) @trusted @nogc nothrow;