When this line (io.c) is called upon initialising ruby with ruby_init() or ruby_setup() and the library is built with VS2015 x86 Native Tools Command Prompt, fileno(stdin) returns -2 and errno is set to 13. This raises a ruby exception and fails setup. The library has been tested with /MD and /MDd and with 2.4.2 and 2.5.0
I am linking to the static library from a win32 application (not console app) set to use the same runtime version as the ruby build. I have tried setting up a console with AllocConsole() and assigning *stdin to this console before initializing ruby, but it doesn't help.
Thanks my issue is very similar. The issue you linked to presents some undocumented requirements. When I try calling rb_w32_sysinit it crashes on this line:
I deleted all traces of the ucrtbased.dll on my system which were of version 10.0.15063.137 and copied version 10.0.10240.16384 to C:\Windows\SysWOW64 (I'm on Windows 10). The correct working version is the one from the Windows 10 SDK.