Daniel Berger
2012-Jul-12 14:57 UTC
[Win32utils-devel] Trouble with get_osfhandle and MSVC
Hi, Ruby 1.9.3-p194 I''m having trouble getting get_osfhandle to work with a Ruby compiled with MSVC. With mingw this code works fine, but with MSVC I get an invalid handle error. require ''windows/handle'' require ''windows/error'' include Windows::Handle include Windows::Error file = File.open(''test.txt'') handle = get_osfhandle(file.fileno) if handle == INVALID_HANDLE_VALUE || handle == 0 raise get_last_error end file.close Any ideas? Regards, Dan
Hi, 2012/7/12 Daniel Berger <djberg96 at gmail.com>:> Hi, > > Ruby 1.9.3-p194 > > I''m having trouble getting get_osfhandle to work with a Ruby compiled > with MSVC. With mingw this code works fine, but with MSVC I get an > invalid handle error. > > require ''windows/handle'' > require ''windows/error'' > > include Windows::Handle > include Windows::Error > > file = File.open(''test.txt'') > handle = get_osfhandle(file.fileno) > > if handle == INVALID_HANDLE_VALUE || handle == 0 > raise get_last_error > end > > file.close > > Any ideas? >As you already know, this is due to the version mismatch of the msvcrt.dll. The source code of windows/api.rb line #11 - 21 if CONFIG[''host_os''].split(''_'')[1] if CONFIG[''host_os''].split(''_'')[1].to_i >= 80 && File.exists?(File.join(CONFIG[''bindir''], ''ruby.exe.manifest'')) then MSVCRT_DLL = ''msvcr'' + CONFIG[''host_os''].split(''_'')[1] else MSVCRT_DLL = ''msvcrt'' end else MSVCRT_DLL = ''msvcrt'' end should be if CONFIG[''host_os''].split(''_'')[1] if CONFIG[''host_os''].split(''_'')[1].to_i >= 80 then MSVCRT_DLL = ''msvcr'' + CONFIG[''host_os''].split(''_'')[1] else MSVCRT_DLL = ''msvcrt'' end else MSVCRT_DLL = ''msvcrt'' end Regards, Park Heesob
Daniel Berger
2012-Jul-13 15:55 UTC
[Win32utils-devel] Trouble with get_osfhandle and MSVC
Hi, On Thu, Jul 12, 2012 at 8:10 PM, Heesob Park <phasis at gmail.com> wrote:> Hi, > > 2012/7/12 Daniel Berger <djberg96 at gmail.com>: >> Hi, >> >> Ruby 1.9.3-p194 >> >> I''m having trouble getting get_osfhandle to work with a Ruby compiled >> with MSVC. With mingw this code works fine, but with MSVC I get an >> invalid handle error. >> >> require ''windows/handle'' >> require ''windows/error'' >> >> include Windows::Handle >> include Windows::Error >> >> file = File.open(''test.txt'') >> handle = get_osfhandle(file.fileno) >> >> if handle == INVALID_HANDLE_VALUE || handle == 0 >> raise get_last_error >> end >> >> file.close >> >> Any ideas? >> > As you already know, this is due to the version mismatch of the msvcrt.dll. > The source code of windows/api.rb line #11 - 21 > > if CONFIG[''host_os''].split(''_'')[1] > if CONFIG[''host_os''].split(''_'')[1].to_i >= 80 && > File.exists?(File.join(CONFIG[''bindir''], ''ruby.exe.manifest'')) > then > MSVCRT_DLL = ''msvcr'' + CONFIG[''host_os''].split(''_'')[1] > else > MSVCRT_DLL = ''msvcrt'' > end > else > MSVCRT_DLL = ''msvcrt'' > end > > should be > > if CONFIG[''host_os''].split(''_'')[1] > if CONFIG[''host_os''].split(''_'')[1].to_i >= 80 > then > MSVCRT_DLL = ''msvcr'' + CONFIG[''host_os''].split(''_'')[1] > else > MSVCRT_DLL = ''msvcrt'' > end > else > MSVCRT_DLL = ''msvcrt'' > end > > Regards, > > Park HeesobOops, thanks. I''ve fixed it and pushed out a new version. Cheers, Dan