Stating upfront, I'm not a Windows programmer.
I am trying to develop a Node extension, which is working fine on macOS, but on Windows I need to include a header with this definition:
typedef DWORD WINAPI (*CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD);
I understand that WINAPI
is a #define
for __stdcall
, which is a calling convention on win32.
The line doesn't compile with MSVS 2017: winportfactory.h(54): error C2059: syntax error: '('
because of __stdcall
.
I think I have MSVS set for win32. I have called npm config set arch ia32
and my binding.gyp
looks like this:
"defines": [
"__WIN32__" # Needed to include the right subheader
],
"msvs_configuration_platform": "win32",
"msvs_settings": {
"VCCLCompilerTool": {
"AdditionalOptions": [
"/EHsc",
"/std:c++17"
]
}
}
Here is the complete compiler invocation:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX64\x86\CL.exe /c /I"C:\Users\danni\.node-gyp\10.15.1\include\node" /I"C:\Use
rs\danni\.node-gyp\10.15.1\src" /I"C:\Users\danni\.node-gyp\10.15.1\deps\openssl\config" /I"C:\Users\danni\.node-gyp\10.15.1\deps\openssl\openssl\include" /I"C:\Users\danni\.
node-gyp\10.15.1\deps\uv\include" /I"C:\Users\danni\.node-gyp\10.15.1\deps\zlib" /I"C:\Users\danni\.node-gyp\10.15.1\deps\v8\include" /I..\src /I..\extern\bossa\src /I..\node
_modules\nan /I..\src\compat /Z7 /nologo /W3 /WX- /diagnostics:classic /MP /Ox /Ob2 /Oi /Ot /Oy /GL /D NODE_GYP_MODULE_NAME=bossa /D USING_UV_SHARED=1 /D USING_V8_SHARED=1 /D
V8_DEPRECATION_WARNINGS=1 /D WIN32 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _HAS_EXCEPTIONS=0 /D VERSION=bossajs /D __WIN32__ /D BUILDING_NODE_EXTENSION /
D _WINDLL /GF /Gm- /MT /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /GR- /Fo"Release\obj\bossa\\" /Fd"Release\obj\bossa\vc141.pdb" /Gd /TP /wd4351 /wd4355 /wd4800
/wd4251 /wd4275 /wd4244 /wd4267 /analyze- /FC /errorReport:queue /EHsc /std:c++17 ..\src\index.cc ..\src\bossajs.cc ..\src\observer.cc ..\src\connectworker.cc MORE_FILES "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\src\win_delay_load_hook.cc"
index.cc
Where am I going wrong?
I've discovered the reason it fails is not because they're turned off or some config issue, but because MSVC disagrees on the order of the tokens.
It needs to be:
typedef DWORD (WINAPI *CM_Open_DevNode_Key)(DWORD, DWORD, DWORD, DWORD, ::PHKEY, DWORD);
This answer has more details.