Build failure on Windows in [email protected]
due to GetModuleHandle
LPCWSTR conversion issue #3126
Description
Description
After upgrading to [email protected]
, I encountered a build failure on Windows due to an incorrect function call in win_delay_load_hook.cc
. The issue is caused by GetModuleHandle
, which expects a wide string (LPCWSTR
) but is receiving a narrow string (char*
).
This happens on both local hardware and GitHub runners.
Error Message
C:\Users\myuser\AppData\Local\Yarn\Data\global\node_modules\node-gyp\src\win_delay_load_hook.cc(32,36): error C2664: 'HMODULE GetModuleHandleW(LPCWSTR)': cannot convert argument 1 from 'const char [12]' to 'LPCWSTR'
Additional Context
This issue appears to be introduced by changes in #2834, which were merged and released as part of [email protected]
Detailed logs (GitHub Actions run): logs from the failed build
Affected Versions
- node-gyp:
11.1.0
- Node.js: Any, I've tested w/
18.x
,20.x
,22.x
- OS: Windows 10 (x64), Windows GitHub runners
Proposed Fix
I'm not a C++ expert, but I attempted a modification in win_delay_load_hook.cc
to explicitly use GetModuleHandleA
(ANSI) instead of GetModuleHandle
, which defaults to GetModuleHandleW
(wide-character version).
Change this:
m = GetModuleHandle("libnode.dll");
to this:
m = GetModuleHandleA("libnode.dll");
If this sounds like a reasonable solution, I can open a PR.
Would appreciate any comments from the maintainers.