lifecycle: hook only the title window, end through ExitProcess, fix unregister race

- Only the title's first top-level window (no parent, not WS_CHILD, not
  WS_EX_TOOLWINDOW) is fitted to the work area and gets the SC_CLOSE hook;
  WM_NCDESTROY releases the claim. Other windows the title creates are left
  alone instead of ending the process on close.
- The suspend thread and the 1 s deadline end the run through the title's own
  ExitProcess shim (process.cpp end_run), so the host finishes its cleanup,
  instead of TerminateProcess.
- Suspend callbacks run under the (now recursive) registration lock and each
  id is looked up again before its call, so a routine never runs after
  UnregisterAppStateChangeNotification returned, and an unregister from inside
  a callback works.
- docs/runtime_imports.md: speech, XLauncher and XAppCapture text matches the
  code; new lifecycle shim paragraph.
- lifecycle_test: unregister-from-callback and title-window claim checks.

AI-assisted. Tested: lifecycle_test (29 checks), xgameruntime_offline_test
(69 checks), docs and gdk_runtime_calls pytest; clang 23 / mingw x64.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
andretuta
2026-11-24 03:00:33 -03:00
parent 82dcf6dedc
commit a02134a9c6
3 changed files with 165 additions and 44 deletions

View File

@ -64,6 +64,14 @@ Since the library-loader shims (`runtime/shims/library_loader.cpp`), a module's
The process shim (`runtime/shims/process.cpp`) serves `ExitProcess` and `GetCommandLineA/W` the same way: through `kernel32`, `kernelbase`, and `api-ms-win-core-processthreads-l1-1-0` and `api-ms-win-core-processenvironment-l1-1-0`, the sets the API-set umbrella libraries (`OneCore_apiset.lib`, `mincore.lib`) bind them to. `vcomp140.dll` imports `ExitProcess` from the first of these. The UCRT's `_get_narrow_winmain_command_line` and `_get_wide_winmain_command_line` are served too, so a `WinMain` executable gets the game's command line as `lpCmdLine`. `abort()` raises `SIGABRT` when the guest installed a handler (the guest's `signal()` import binds to the host CRT, so its table is the one raised here); with the default or ignore disposition, or a handler that returns, the run still ends with code 3. `run_tiny_game_abort_exit_codes` compares that with a native run of the stand-in image. The table above is `gta6rt --dry-run` on each DLL at the commit that added this paragraph.
The lifecycle shim (`runtime/shims/lifecycle.cpp`) serves `RegisterAppStateChangeNotification` and
`UnregisterAppStateChangeNotification` under `api-ms-win-core-psm-appnotify-l1-1-0`, `-l1-1-1` and `kernelbase.dll`, and
`CreateWindowExW`/`CreateWindowExA` under `user32.dll` and the two `ext-ms-win-rtcore-ntuser-window-l1-1-*` sets. Only the
title's first top-level window (no parent, not a child, not a tool window) is fitted to the work area and hooked: its
`SC_CLOSE` runs the registered suspend callbacks with `quiesced` TRUE under the registration lock, then the run ends
through the title's own `ExitProcess`, so the host finishes its cleanup. A 1 s deadline ends the run the same way if the
callbacks have not returned.
The shims added since account for the rest of the difference from the first version of the table. The UCRT's `_configure_narrow_argv`, `_configure_wide_argv`, `__p___argc`, `__p___wargv` and `abort` are served by `runtime/shims/process.cpp`, which is why almost every DLL gained one or two. The file-system calls listed in *Console paths and the write overlay* below (`CreateFile2`, `CopyFile2`, `CreateDirectoryW`, `FindFirstFileExW`, `SetFileAttributesW` and the rest) account for `msvcp140.dll`, `vcomp140.dll`, `Bink2Scarlett.dll`'s `CreateFile2` and part of the two HTTP clients. `winhttp.dll` is a module the shims own (*WinHTTP offline* below), so every `WinHttp*` import binds to it: 15 in `libHttpClient.GDK.dll` (all 16 but `WinHttpCrackUrl`) and 15 in `XCurl.dll` (all but `WinHttpQueryOption`). That is why the two HTTP clients moved the most: 11 to 26 and 9 to 24 shim imports.
The UCRT argv configuration imports honor the executable's startup mode. Each run starts with `argc == 0` and
@ -450,13 +458,18 @@ on the executable, the rest is not:
- **Accessibility and speech** (`IXAccessibilityImpl2`, slots 3-21): `XHighContrastGetMode` (5) answers Off and
`XClosedCaptionSetEnabled` (4) is accepted. No voice is installed: `XSpeechSynthesizerEnumerateInstalledVoices`
(8) calls back zero times and returns `S_OK`, `XSpeechSynthesizerCreate` (9) fails (`E_FAIL`) with a null handle,
and the handle calls (10-16, 21: close, default and custom voice, streams from text and SSML, stream size and
data) refuse the handle they were never given (`E_INVALIDARG`, outputs zeroed). The closed-caption properties (3)
and the speech-to-text display calls (6, 7, 17-20) fail with `E_FAIL`, writing nothing: their parameter lists
are not in the docs' layout.
- **`XLauncherImpl`** (`IXLauncherImpl`, slots 3-5): `XLaunchUri`, `XDisplayAcquireTimeoutDeferral` (null handle)
and `XDisplayCloseTimeoutDeferralHandle` fail with `E_FAIL`; nothing is launched.
(8) calls back zero times and returns `S_OK`. `XSpeechSynthesizerCreate` (9) hands out a silent synthesizer handle
(`E_POINTER` for a null out pointer). Close (10), set default voice (11) and set custom voice (12) accept that handle
and refuse any other with `E_INVALIDARG`. Streams from text (13) and SSML (21) are created from it and return a
stream handle; its close (14) accepts it. Stream size (15) reports 44 bytes and stream data (16) copies them: a valid
RIFF/WAVE header for 16 kHz, 16-bit mono PCM with zero data bytes, so a title that plays narration reads a silent
stream (a buffer under 44 bytes gets `ERROR_INSUFFICIENT_BUFFER`). A foreign handle on 15 or 16 gets `E_INVALIDARG`,
outputs zeroed. The closed-caption properties (3) and the speech-to-text display calls (6, 7, 17-20) fail with
`E_FAIL`, writing nothing: their parameter lists are not in the docs' layout.
- **`XLauncherImpl`** (`IXLauncherImpl`, slots 3-5): `XLaunchUri` fails with `E_FAIL`; nothing is launched.
`XDisplayAcquireTimeoutDeferral` (4) creates a Win32 `PowerRequestDisplayRequired` request and returns its handle (a
failing `PowerCreateRequest` or `PowerSetRequest` returns the Win32 error as an HRESULT).
`XDisplayCloseTimeoutDeferralHandle` (5) clears that request and closes the handle, so the display may sleep again.
- **ASSUMPTION:** the parameter lists of the speech calls and `XHighContrastGetMode` (Off is 0), from the GDK
reference; only the argument counts were measured, from `tools/gdk_runtime_calls.py` on the executable.
- **HDR:** `XDisplayTryEnableHdrMode` answers Disabled, because the host output is SDR. With `LEONIDA_HDR=1` it
@ -484,11 +497,12 @@ layout with the documented argument count, and each behaves as Microsoft's refer
| Class | Interface asked for | Slots (args after `this`) | Offline behaviour |
|---|---|---|---|
| `XGameRuntimeFeatureImpl` | its class id | 3 `XGameRuntimeIsFeatureAvailable` (1, returns `bool`) | True when `QueryApiImpl` serves the class the feature's functions go through (whichever `xgameruntime*.cpp` serves it) and the feature is documented for Windows: today XAccessibility, XSpeechSynthesizer, XLauncher, XAsync, XAsyncProvider, XTaskQueue, XThread, XError, XGame, XGameSave, XGameUI, XNetworking, XPackage, XPersistentLocalStorage, XStore, XSystem, XUser, XGameEvent, XGameStreaming. False for XDisplay (served, but documented for the consoles only), for the classes not served (XAppCapture, XGameInvite) and for values past the enum |
| `XGameRuntimeFeatureImpl` | its class id | 3 `XGameRuntimeIsFeatureAvailable` (1, returns `bool`) | True when `QueryApiImpl` serves the class the feature's functions go through (whichever `xgameruntime*.cpp` serves it) and the feature is documented for Windows: today XAccessibility, XAppCapture, XSpeechSynthesizer, XLauncher, XAsync, XAsyncProvider, XTaskQueue, XThread, XError, XGame, XGameSave, XGameUI, XNetworking, XPackage, XPersistentLocalStorage, XStore, XSystem, XUser, XGameEvent, XGameStreaming. False for XDisplay (served, but documented for the consoles only), for the classes not served (XGameInvite) and for values past the enum |
| `XSystemAnalyticsImpl` | its class id | 3 `XSystemGetAnalyticsInfo` (1: the result's address, as MSVC passes a returned struct to a member function) | The named export's `XSystemAnalyticsInfo` |
Not served yet, though `libHttpClient.GDK.dll` has thunks for them: `XAppCaptureImpl` and `XGameInviteImpl`,
among others.
Not served yet, though `libHttpClient.GDK.dll` has thunks for them: `XGameInviteImpl`, among others.
`XAppCaptureImpl` is served offline (`runtime/shims/xgameruntime_offline.cpp`): its class and interface ids answer,
`XAppCaptureTakeScreenshot` (5) returns `ERROR_NOT_SUPPORTED`, and slots 3 and 4 go through the unknown-slot path.
Which classes the package's GDK modules reference, from a byte search for the class and interface GUIDs that
xgameruntime-docs lists (16-byte in-memory form, every `.dll` of the package; counts only, nothing else read):
@ -519,9 +533,9 @@ therefore needs no module name beyond the `xgameruntime.dll` it already has, whi
| Class | Thunks | Referenced | Served |
|---|---:|---:|---|
| `XAccessibilityImpl` | 10 | 9 | no |
| `XAppCaptureImpl` | 1 | 1 | no |
| `XLauncherImpl` | 3 | 3 | no |
| `XAccessibilityImpl` | 10 | 9 | yes |
| `XAppCaptureImpl` | 1 | 1 | yes |
| `XLauncherImpl` | 3 | 3 | yes |
| `XDisplayImpl` | 1 | 1 | yes |
| `XGameEventImpl` | 1 | 1 | yes |
| `XGameImpl` | 2 | 2 | yes |
@ -537,10 +551,10 @@ therefore needs no module name beyond the `xgameruntime.dll` it already has, whi
| `XThreadingImpl` | 18 | 17 | yes |
| `XUserImpl` | 21 | 21 | yes |
"Served" is the tool's answer for the runtime sources at that commit. The three that are not: `XAccessibilityImpl`
(the speech-synthesizer slots 8-13, 15, 16 and 21 are referenced; slot 14 is not), `XAppCaptureImpl` (slot 5,
`XAppCaptureTakeScreenshot`) and `XLauncherImpl` (slots 3-5: `XLaunchUri` and the two display timeout-deferral calls).
Open pull requests serve them: #4235, #4307 and #4248. The slots of `XUserImpl`, `XStoreImpl` and `XGameSaveImpl` the
"Served" is the tool's answer for the runtime sources on this branch (`served_classes` over every `runtime/shims/*.cpp`):
every class in the table is served now, `XAppCaptureImpl` and `XLauncherImpl` included. The executable references the
speech-synthesizer slots 8-13, 15, 16 and 21 (slot 14 is not), `XAppCaptureImpl` slot 5 (`XAppCaptureTakeScreenshot`)
and `XLauncherImpl` slots 3-5 (`XLaunchUri` and the two display timeout-deferral calls). The slots of `XUserImpl`, `XStoreImpl` and `XGameSaveImpl` the
executable calls, and the argument counts the tool estimates from the registers, are in the report the tool writes.
`XErrorImpl`, which `XCurl.dll` and `libHttpClient.GDK.dll` call, is not among the executable's classes.

View File

@ -8,9 +8,9 @@
// This shim provides:
// - RegisterAppStateChangeNotification / UnregisterAppStateChangeNotification on api-ms-win-core-psm-appnotify-*
// and kernelbase.dll;
// - CreateWindowExW / CreateWindowExA on user32.dll and ext-ms-win-rtcore-ntuser-window-*, fitting oversized
// top-level windows into the primary monitor work area and subclassing them so SC_CLOSE runs registered suspend
// callbacks before exiting cleanly.
// - CreateWindowExW / CreateWindowExA on user32.dll and ext-ms-win-rtcore-ntuser-window-*, fitting the title's first
// top-level window into the primary monitor work area and subclassing it so SC_CLOSE runs registered suspend
// callbacks before the run ends.
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
@ -47,9 +47,10 @@ struct Registration {
constexpr wchar_t kTitleProcProp[] = L"leonida.title.wndproc";
constexpr auto kSuspendDeadline = std::chrono::seconds(1);
std::mutex& reg_mutex() {
// Recursive so a callback can unregister from inside run_suspend_callbacks() on the same thread.
std::recursive_mutex& reg_mutex() {
// Intentionally immortal so shutdown/WM_SYSCOMMAND cannot race static destruction.
static auto* m = new std::mutex;
static auto* m = new std::recursive_mutex;
return *m;
}
@ -60,30 +61,58 @@ std::vector<Registration>& reg_list() {
std::atomic<std::uintptr_t> g_next_reg_id{1};
std::atomic<bool> g_ending{false};
std::atomic<HWND> g_title_window{nullptr};
std::vector<Registration> snapshot_registrations() {
// Ends the run through the title's own ExitProcess (process.cpp's game_exit_process -> end_run, which lets the host
// finish its cleanup), not TerminateProcess. Falls back to ExitProcess if the shim table has no binding.
[[noreturn]] void end_title_run() {
using ExitProcessFn = void(__stdcall*)(UINT);
if (auto* exit_process = reinterpret_cast<ExitProcessFn>(rt::shims::find("kernel32.dll", "ExitProcess"))) {
exit_process(0);
}
ExitProcess(0);
}
// Runs every registration still in the list, with the registration lock held for the whole loop: an Unregister on
// another thread waits for the callback in flight, and one from inside a callback re-enters the recursive lock and
// stops the later calls of its id. Ids come from a snapshot and are looked up again, so an entry removed by an
// earlier callback is skipped.
// ponytail: a callback that blocks on another thread which is itself in Register/Unregister stalls until the 1 s
// deadline ends the run.
void run_suspend_callbacks() {
std::lock_guard lock(reg_mutex());
return reg_list();
std::vector<std::uintptr_t> ids;
for (const auto& r : reg_list()) ids.push_back(r.id);
for (const auto id : ids) {
AppStateRoutine routine = nullptr;
void* context = nullptr;
for (const auto& r : reg_list()) {
if (r.id == id) {
routine = r.routine;
context = r.context;
break;
}
}
if (routine) routine(TRUE, context);
}
}
void trigger_suspend_and_exit() {
if (g_ending.exchange(true, std::memory_order_seq_cst)) return;
auto callbacks = snapshot_registrations();
std::fprintf(stderr, "[rt] lifecycle: window closed; running %zu suspend routine(s)\n", callbacks.size());
std::fprintf(stderr, "[rt] lifecycle: window closed; running %zu suspend routine(s)\n",
registered_notification_count());
// Run suspend callbacks off the UI thread so callbacks that synchronize with the window thread do not deadlock.
std::thread([callbacks = std::move(callbacks)]() {
for (const auto& entry : callbacks) {
if (entry.routine) entry.routine(TRUE, entry.context);
}
std::thread([]() {
run_suspend_callbacks();
std::fprintf(stderr, "[rt] lifecycle: title suspended; exiting\n");
TerminateProcess(GetCurrentProcess(), 0);
end_title_run();
}).detach();
std::thread([]() {
std::this_thread::sleep_for(kSuspendDeadline);
std::fprintf(stderr, "[rt] lifecycle: suspend deadline elapsed; exiting\n");
TerminateProcess(GetCurrentProcess(), 0);
end_title_run();
}).detach();
}
@ -95,6 +124,8 @@ LRESULT CALLBACK lifecycle_wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPAR
const HANDLE prop = GetPropW(hwnd, kTitleProcProp);
if (message == WM_NCDESTROY) {
RemovePropW(hwnd, kTitleProcProp);
HWND expected = hwnd;
g_title_window.compare_exchange_strong(expected, nullptr); // a later main window may be claimed
}
auto original = reinterpret_cast<WNDPROC>(prop);
if (!original) return DefWindowProcW(hwnd, message, wparam, lparam);
@ -109,18 +140,29 @@ void install_window_hook(HWND hwnd) {
SetWindowLongPtrW(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(&lifecycle_wnd_proc));
}
void fit_top_level_window(HWND parent, int& x, int& y, int& width, int& height) {
if (parent != nullptr) return;
// Before CreateWindowEx: a candidate is a top-level, non-child, non-tool window. Returns whether it is one, and fits
// it only when it is the first candidate (no title window claimed yet).
bool prepare_title_window(HWND parent, DWORD style, DWORD ex_style, int& x, int& y, int& width, int& height) {
if (parent != nullptr || (style & WS_CHILD) || (ex_style & WS_EX_TOOLWINDOW)) return false;
if (g_title_window.load() != nullptr) return true;
RECT area{};
if (!SystemParametersInfoW(SPI_GETWORKAREA, 0, &area, 0)) return;
if (!SystemParametersInfoW(SPI_GETWORKAREA, 0, &area, 0)) return true;
const auto [fitted_w, fitted_h] = fit_window_to_area(area, width, height);
if (fitted_w == width && fitted_h == height) return;
if (fitted_w == width && fitted_h == height) return true;
std::fprintf(stderr, "[rt] lifecycle: fitted oversized title window %dx%d -> %dx%d\n", width, height, fitted_w,
fitted_h);
width = fitted_w;
height = fitted_h;
x = area.left + ((area.right - area.left) - width) / 2;
y = area.top + ((area.bottom - area.top) - height) / 2;
return true;
}
// After CreateWindowEx: the first candidate to succeed claims the title window and gets the SC_CLOSE hook.
void adopt_title_window(HWND hwnd, bool candidate) {
if (!hwnd || !candidate) return;
HWND expected = nullptr;
if (g_title_window.compare_exchange_strong(expected, hwnd)) install_window_hook(hwnd);
}
ULONG WINAPI register_app_state_change(AppStateRoutine routine, PVOID context, PVOID* registration) {
@ -144,19 +186,19 @@ void WINAPI unregister_app_state_change(PVOID registration) {
HWND WINAPI create_window_ex_w_shim(DWORD ex_style, LPCWSTR class_name, LPCWSTR window_name, DWORD style, int x, int y,
int width, int height, HWND parent, HMENU menu, HINSTANCE instance, LPVOID param) {
fit_top_level_window(parent, x, y, width, height);
const bool candidate = prepare_title_window(parent, style, ex_style, x, y, width, height);
const HWND hwnd =
::CreateWindowExW(ex_style, class_name, window_name, style, x, y, width, height, parent, menu, instance, param);
if (hwnd && !parent) install_window_hook(hwnd);
adopt_title_window(hwnd, candidate);
return hwnd;
}
HWND WINAPI create_window_ex_a_shim(DWORD ex_style, LPCSTR class_name, LPCSTR window_name, DWORD style, int x, int y,
int width, int height, HWND parent, HMENU menu, HINSTANCE instance, LPVOID param) {
fit_top_level_window(parent, x, y, width, height);
const bool candidate = prepare_title_window(parent, style, ex_style, x, y, width, height);
const HWND hwnd =
::CreateWindowExA(ex_style, class_name, window_name, style, x, y, width, height, parent, menu, instance, param);
if (hwnd && !parent) install_window_hook(hwnd);
adopt_title_window(hwnd, candidate);
return hwnd;
}
@ -181,9 +223,7 @@ std::size_t registered_notification_count() {
}
void invoke_suspend_callbacks_for_test() {
for (const auto& entry : snapshot_registrations()) {
if (entry.routine) entry.routine(TRUE, entry.context);
}
run_suspend_callbacks();
}
} // namespace rt::lifecycle

View File

@ -39,11 +39,25 @@ void WINAPI on_app_state(BOOLEAN quiesced, PVOID context) {
}
}
using UnregFn = void(WINAPI*)(PVOID);
UnregFn g_unreg = nullptr;
// Context for a callback that unregisters `target` (another registration, or its own handle) when it runs.
struct UnregProbe {
int calls = 0;
PVOID target = nullptr;
};
void WINAPI on_app_state_unregister(BOOLEAN, PVOID context) {
auto* probe = static_cast<UnregProbe*>(context);
++probe->calls;
if (probe->target) g_unreg(probe->target);
}
} // namespace
int main() {
using RegFn = ULONG(WINAPI*)(void(WINAPI*)(BOOLEAN, PVOID), PVOID, PVOID*);
using UnregFn = void(WINAPI*)(PVOID);
using CreateExWFn = HWND(WINAPI*)(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE,
LPVOID);
@ -60,6 +74,7 @@ int main() {
"CreateWindowExW resolves through user32 and ext-ms-win-rtcore-ntuser-window");
check(!rt::shims::owns_dll("user32.dll"), "user32.dll stays partially overridden");
if (!reg || !unreg || !create_w) return 1;
g_unreg = unreg;
// 1. Parameter validation and registration / unregistration / suspend dispatch.
PVOID handle_a = nullptr, handle_b = nullptr;
@ -82,6 +97,33 @@ int main() {
unreg(handle_b);
check(rt::lifecycle::registered_notification_count() == 0, "all registrations removed");
// 1b. A callback that unregisters a later registration: the later one is skipped during the same dispatch.
PVOID handle_later = nullptr, handle_first = nullptr;
SuspendProbe later_probe{};
UnregProbe first_probe{};
check(reg(&on_app_state_unregister, &first_probe, &handle_first) == ERROR_SUCCESS,
"register unregistering callback");
check(reg(&on_app_state, &later_probe, &handle_later) == ERROR_SUCCESS, "register later callback");
first_probe.target = handle_later;
rt::lifecycle::invoke_suspend_callbacks_for_test();
check(first_probe.calls == 1 && later_probe.calls == 0,
"unregistered later callback does not run in the same dispatch");
check(rt::lifecycle::registered_notification_count() == 1, "later registration is gone, the first remains");
unreg(handle_first);
check(rt::lifecycle::registered_notification_count() == 0, "dispatch test registrations removed");
// 1c. A callback that unregisters itself: no deadlock, it runs once, and it is gone afterwards.
PVOID handle_self = nullptr;
UnregProbe self_probe{};
check(reg(&on_app_state_unregister, &self_probe, &handle_self) == ERROR_SUCCESS,
"register self-unregistering callback");
self_probe.target = handle_self;
rt::lifecycle::invoke_suspend_callbacks_for_test();
check(self_probe.calls == 1 && rt::lifecycle::registered_notification_count() == 0,
"self-unregistering callback runs once and is removed without deadlock");
rt::lifecycle::invoke_suspend_callbacks_for_test();
check(self_probe.calls == 1, "removed self-unregistering callback is not called again");
// 2. Oversized window scaling math.
const RECT area{0, 0, 1920, 1040};
const auto fitted_4k = rt::lifecycle::fit_window_to_area(area, 3840, 2160);
@ -104,6 +146,31 @@ int main() {
DestroyWindow(hwnd);
}
// 4. Only the title's first top-level window is hooked; a window is released when it is destroyed. Hidden windows
// only: no SC_CLOSE is posted.
const wchar_t* kHookProp = L"leonida.title.wndproc";
WNDCLASSEXW wc{};
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = DefWindowProcW;
wc.hInstance = GetModuleHandleW(nullptr);
wc.lpszClassName = L"LeonidaLifecycleTest";
RegisterClassExW(&wc);
const DWORD kMain = WS_OVERLAPPEDWINDOW;
const wchar_t* kClass = L"LeonidaLifecycleTest";
HWND main_win = create_w(0, kClass, L"main", kMain, 0, 0, 64, 64, nullptr, nullptr, nullptr, nullptr);
check(main_win && GetPropW(main_win, kHookProp) != nullptr, "first parentless window is the hooked title window");
HWND second = create_w(0, kClass, L"second", kMain, 0, 0, 64, 64, nullptr, nullptr, nullptr, nullptr);
check(second && GetPropW(second, kHookProp) == nullptr, "a second parentless window is not hooked");
HWND tool = create_w(WS_EX_TOOLWINDOW, L"LeonidaLifecycleTest", L"tool", WS_POPUP, 0, 0, 64, 64, nullptr, nullptr,
nullptr, nullptr);
check(tool && GetPropW(tool, kHookProp) == nullptr, "a WS_EX_TOOLWINDOW window is not hooked");
if (main_win) DestroyWindow(main_win);
HWND again = create_w(0, kClass, L"again", kMain, 0, 0, 64, 64, nullptr, nullptr, nullptr, nullptr);
check(again && GetPropW(again, kHookProp) != nullptr, "after the title window is destroyed, a new one is hooked");
for (HWND w : {second, tool, again}) {
if (w) DestroyWindow(w);
}
std::printf("%d check(s), %d failure(s)\n", g_checks, g_failures);
return g_failures ? 1 : 0;
}