简体   繁体   English

_setmode( _fileno(stdin), _O_BINARY) 在使用 /MD 编译时等待 Enter 键

[英]_setmode( _fileno(stdin), _O_BINARY) waits for Enter key when compiled with /MD

I am embedding a Java VM (JVM) using JNI in a DLL for a native application on Windows (altv-server.exe).我在 DLL 中使用 JNI 嵌入 Java VM (JVM),用于 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. JNI_CreateJavaVM 在内部调用_setmode( _fileno(stdin), _O_BINARY ) ,这会导致进程在继续之前等待 Enter 键输入。 The function succeeds but the waiting for input is undesirable. function 成功,但等待输入是不可取的。

The mode is in _O_TEXT prior to calling _setmode( _fileno(stdin), _O_BINARY) .在调用_setmode( _fileno(stdin), _O_BINARY)之前,模式处于_O_TEXT中。

This behaviour happens when the DLL is built with /MD .当 DLL 使用/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. 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 .服务器是使用/MD构建的,因此 DLL 也需要使用/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.调用_setmode(_fileno(stdin), _O_BINARY)会导致这种不良行为。

Starting that thread after _setmode(_fileno(stdin), _O_BINARY) resolved this particular problem._setmode(_fileno(stdin), _O_BINARY)之后启动该线程解决了这个特定问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM