gpt4 book ai didi

c++ - GetLastInputInfo 在 Node 插件中失败

转载 作者:行者123 更新时间:2023-11-30 02:38:49 25 4
gpt4 key购买 nike

我的目标是制作一个模块,提供对上次用户交互的访问(客户端应用程序 - 而不是服务器应用程序)。 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)

有什么想法吗?

最佳答案

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

The size of the structure, in bytes. This member must be set to sizeof(LASTINPUTINFO).

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

关于c++ - GetLastInputInfo 在 Node 插件中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30387379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com