【问题标题】:Windows GetTickCount in RubyRuby 中的 Windows GetTickCount
【发布时间】:2011-04-14 11:32:50
【问题描述】:

是否可以在 Ruby 中获取当前窗口的 TickCount?

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

【问题讨论】:

    标签: ruby windows gettickcount


    【解决方案1】:

    是的,例如FFI 是可能的。 首先,你应该安装ffigem:

    gem install ffi
    

    然后附上这个函数:

    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】:

      使用windows api:

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

      Time.now - t.call() / 1000.0 获取机器启动时间

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-28
        • 1970-01-01
        • 2011-02-26
        • 2011-06-16
        • 1970-01-01
        • 2012-12-08
        相关资源
        最近更新 更多