【问题标题】:GetLastInputInfo fails in node addonGetLastInputInfo 在节点插件中失败
【发布时间】:2015-05-22 02:21:44
【问题描述】:

我的目标是制作一个模块,该模块提供对用户交互最后一次的访问(客户端应用程序 - 不是服务器应用程序)。 Windows API 有一个名为GetLastInputInfo (https://msdn.microsoft.com/en-us/library/windows/desktop/ms646302(v=vs.85).aspx) 的函数。下面是应该将时间信息加载到last_input 的代码,它返回 0/1 表示失败/成功。不幸的是,它每次都失败。

插件代码:

#include <node.h>
#include <v8.h>

#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>

using namespace v8;

Handle<Value> TimeSinceInput(const Arguments& args) {
    HandleScope scope;

    LASTINPUTINFO last_input;
    if (::GetLastInputInfo(&last_input)) {
        return scope.Close(String::New("Success!"));
    }
    else {
        return scope.Close(String::New("Failed for some reason!"));
    }
}

void init(Handle<Object> exports) {
    exports->Set(String::NewSymbol("time_since_input"), FunctionTemplate::New(TimeSinceInput)->GetFunction());
}

NODE_MODULE(addon, init)

有什么想法吗?

【问题讨论】:

  • 嗨兰迪!你的插件是公开的吗? :-)

标签: c++ node.js node-gyp node.js-addon


【解决方案1】:

LASTINPUTINFO 结构有成员 cbSize,应该初始化:

结构的大小,以字节为单位。此成员必须设置为 sizeof(LASTINPUTINFO)。

这是在 Windows API 中进行版本控制的常用方法。

【讨论】:

  • 完美。我错过了文档中的那个注释。感谢您的帮助和解释!
猜你喜欢
  • 2021-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-02
  • 1970-01-01
  • 2014-06-18
  • 1970-01-01
相关资源
最近更新 更多