Skip to content

Commit b7d8234

Browse files
nornagoncodebytere
authored andcommitted
docs: add some troubleshooting info related to win_delay_load_hook (electron#16764)
* docs: add some troubleshooting info related to win_delay_load_hook * appease lint
1 parent d53b516 commit b7d8234

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/tutorial/using-native-node-modules.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,34 @@ the loading executable instead of looking for `node.dll` in the library search
9999
path (which would turn up nothing). As such, on Electron 4.x and higher,
100100
`'win_delay_load_hook': 'true'` is required to load native modules.
101101

102+
103+
If you get an error like `Module did not self-register`, or `The specified
104+
procedure could not be found`, it may mean that the module you're trying to use
105+
did not correctly include the delay-load hook. If the module is built with
106+
node-gyp, ensure that the `win_delay_load_hook` variable is set to `true` in
107+
the `binding.gyp` file, and isn't getting overridden anywhere. If the module
108+
is built with another system, you'll need to ensure that you build with a
109+
delay-load hook installed in the main `.node` file. Your `link.exe` invocation
110+
should look like this:
111+
112+
```text
113+
link.exe /OUT:"foo.node" "...\node.lib" delayimp.lib /DELAYLOAD:node.exe /DLL
114+
"my_addon.obj" "win_delay_load_hook.obj"
115+
```
116+
117+
In particular, it's important that:
118+
119+
- you link against `node.lib` from _Electron_ and not Node. If you link against
120+
the wrong `node.lib` you will get load-time errors when you require the
121+
module in Electron.
122+
- you include the flag `/DELAYLOAD:node.exe`. If the `node.exe` link is not
123+
delayed, then the delay-load hook won't get a chance to fire and the node
124+
symbols won't be correctly resolved.
125+
- `win_delay_load_hook.obj` is linked directly into the final DLL. If the hook
126+
is set up in a dependent DLL, it won't fire at the right time.
127+
128+
See [node-gyp](https://github.com/nodejs/node-gyp/blob/e2401e1395bef1d3c8acec268b42dc5fb71c4a38/src/win_delay_load_hook.cc) for an example delay-load hook if you're implementing your own.
129+
102130
## Modules that rely on `prebuild`
103131

104132
[`prebuild`](https://github.com/mafintosh/prebuild) provides a way to

0 commit comments

Comments
 (0)