Skip to content

Keep the delay-load failure hook in static builds - #142

Merged
ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:fix/delay-load-hook-static
Sep 23, 2026
Merged

ethindp merged 1 commit into
ethindp:masterfrom
trypsynth:fix/delay-load-hook-static

Conversation

@trypsynth

Copy link
Copy Markdown
Contributor

A static link drops delayimp.cpp. Nothing refers to __pfnDliFailureHook2, so the linker never pulls that object in, and the program ends up with no delay-load failure hook. When a delay-loaded screen reader DLL is missing, the helper raises instead of taking prism's stub, and the process dies.

On a machine without PC-Talker, a statically linked program that initializes that backend:

process didn't exit successfully: `...\deps\scratch-abe0a1c4d8d195b4.exe` (exit code: 0xc06d007e)

0xc06d007e is the delay-load helper's "module not found" exception. The same program linked against prism.dll gets PRISM_ERROR_BACKEND_NOT_AVAILABLE, because the hook sits inside the DLL. The static library does carry the object: prism.lib holds both delayimp and __pfnDliFailureHook2, and the linked executable holds neither.

What this does

delayimp.cpp emits prism_anchor_delayimp, and prism.cpp names it in a /include: directive, the way backend_anchors.h keeps the backend registrars. MSVC only, with the leading underscore on x86.

Testing

Windows x64 and x86, from a Rust program that creates every registered backend and calls initialize on each, on a machine with NVDA running and no other screen reader installed.

Before, statically linked, x64:

== NVDA
   initialize: Ok(())
== PCTalker
error: test failed
  process didn't exit successfully: (exit code: 0xc06d007e)

After, statically linked, x64 and x86, and linked against prism.dll as before:

== NVDA
   initialize: Ok(())
== PCTalker
   initialize: Err(BackendNotAvailable)
== ZDSR
   initialize: Err(BackendNotAvailable)
== BoyPCReader
   initialize: Err(BackendNotAvailable)
== JAWS
   initialize: Err(BackendNotAvailable)
== ZoomText
   initialize: Err(BackendNotAvailable)
== SenseReader
   initialize: Err(BackendNotAvailable)
== OneCore
   initialize: Ok(())
== SAPI
   initialize: Ok(())

@ethindp
ethindp merged commit d123306 into ethindp:master Sep 23, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants