2 * Copyright (C) 2023, Greg Manning <gmanning@rapitasystems.com>
4 * This hook, __pfnDliFailureHook2, is documented in the microsoft documentation here:
5 * https://learn.microsoft.com/en-us/cpp/build/reference/error-handling-and-notification
6 * It gets called when a delay-loaded DLL encounters various errors.
7 * We handle the specific case of a DLL looking for a "qemu.exe",
8 * and give it the running executable (regardless of what it is named).
10 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
11 * See the COPYING.LIB file in the top-level directory.
17 FARPROC WINAPI
dll_failure_hook(unsigned dliNotify
, PDelayLoadInfo pdli
);
20 PfnDliHook __pfnDliFailureHook2
= dll_failure_hook
;
22 FARPROC WINAPI
dll_failure_hook(unsigned dliNotify
, PDelayLoadInfo pdli
) {
23 if (dliNotify
== dliFailLoadLib
) {
24 /* If the failing request was for qemu.exe, ... */
25 if (strcmp(pdli
->szDll
, "qemu.exe") == 0) {
26 /* Then pass back a pointer to the top level module. */
27 HMODULE top
= GetModuleHandle(NULL
);
31 /* Otherwise we can't do anything special. */