\_setmode(\_fileno(stdin), \_O_BINARY)在使用/MD编译时会等待按下Enter键。

huangapple go评论98阅读模式
英文:

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

问题

我正在使用JNI在DLL中嵌入Java虚拟机(JVM),以供Windows上的本地应用程序(altv-server.exe)使用。在内部,JNI_CreateJavaVM调用_setmode(_fileno(stdin),_O_BINARY),这会导致进程在继续之前等待按下Enter键。该函数调用成功,但等待输入的行为是不希望的。

在调用_setmode(_fileno(stdin),_O_BINARY)之前,模式为_O_TEXT

当使用/MD构建DLL时会出现此行为。
使用/MDd时,从DLL调用_setmode不会等待输入,但仍然从jvm.dll中进行的函数调用会导致进程等待输入。
服务器是使用/MD构建的,因此DLL也需要使用/MD构建。

英文:

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.

答案1

得分: 1

看起来原生应用程序有一个正在从stdin读取的线程。调用_setmode(_fileno(stdin), _O_BINARY)会导致这种不良行为。

_setmode(_fileno(stdin), _O_BINARY)之后启动该线程解决了这个特定的问题。

英文:

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.

huangapple
  • 本文由 发表于 2020年7月25日 15:10:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63085456.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定