I am embedding a Java VM (JVM) using JNI in a DLL for a native application on Windows (altv-server.exe). Internally JNI_CreateJavaVM calls _setmode( _fileno(stdin), _O_BINARY ) which causes the process to wait for Enter key input before it continues. The function succeeds but the waiting for input is undesirable.
The mode is in _O_TEXT prior to calling _setmode( _fileno(stdin), _O_BINARY).
This behaviour happens when the DLL is built with /MD.
With /MDd, calling _setmode from the DLL will not wait for input, but the function call made from jvm.dll still causes the process to wait for input.
The server is built with /MD, and so it is required by the DLL to also be built with /MD.
It appears that the native application had a thread that was reading from stdin. Calling
_setmode(_fileno(stdin), _O_BINARY)causes this undesirable behaviour.Starting that thread after
_setmode(_fileno(stdin), _O_BINARY)resolved this particular problem.