Windows GetTickCount in Ruby

不想你离开。 提交于 2019-12-13 05:44:43

问题


Is it possible go get the current windows TickCount in Ruby?

(http://msdn.microsoft.com/en-us/library/ms724408%28v=vs.85%29.aspx)


回答1:


Yes, it's possible with FFI for example. At first, you should install ffi gem:

gem install ffi

And then attach this function:

require 'ffi'
module Foo
  extend FFI::Library

  ffi_lib "kernel32.dll"
  ffi_convention :stdcall

  attach_function :get_tick_count, :GetTickCount, [ ], :int
end
puts Foo.get_tick_count #=> 107073812



回答2:


use windows api:

require 'Win32API'

t = Win32API.new("kernel32", "GetTickCount", nil, 'L')
t.call()

or Time.now - t.call() / 1000.0 to get a time when machine was booted



来源:https://stackoverflow.com/questions/5662568/windows-gettickcount-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!