C++ GetLastInputInfo在节点加载项中失败

C++ GetLastInputInfo在节点加载项中失败,c++,node.js,node-gyp,node.js-addon,C++,Node.js,Node Gyp,Node.js Addon,我的目标是制作一个模块,提供对上次用户交互的访问(客户端应用程序-而不是服务器应用程序)。Windows API有一个名为GetLastInputInfo()的函数。下面是将时间信息加载到last\u input中的代码,如果失败/成功,则返回0/1。不幸的是,它每次都失败 加载项代码: #include <node.h> #include <v8.h> #define WINDOWS_LEAN_AND_MEAN #include <windows.h>

我的目标是制作一个模块,提供对上次用户交互的访问(客户端应用程序-而不是服务器应用程序)。Windows API有一个名为
GetLastInputInfo
()的函数。下面是将时间信息加载到
last\u 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)
#包括
#包括
#定义WINDOWS\u LEAN\u和\u MEAN
#包括
使用名称空间v8;
句柄TimeSinceInput(常量参数和参数){
手镜镜;
LASTINPUTINFO last_输入;
if(::GetLastInputInfo(&last_input)){
返回scope.Close(字符串::New(“Success!”);
}
否则{
返回scope.Close(字符串::New(“由于某种原因失败!”);
}
}
void init(句柄导出){
exports->Set(字符串::NewSymbol(“自输入以来的时间”),FunctionTemplate::New(TimeSinceInput)->GetFunction();
}
节点_模块(加载项,初始化)

有什么想法吗?

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

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


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

Perfect。我在文件里漏掉了那张纸条。谢谢你的帮助和解释!嗨,兰迪!您的插件是否公开可用?:-)