Windows GetTickCount in Ruby

2019-08-29 11:56发布

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

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

2条回答
家丑人穷心不美
2楼-- · 2019-08-29 12:35

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
查看更多
姐就是有狂的资本
3楼-- · 2019-08-29 12:35

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

查看更多
登录 后发表回答