从 node.js msg 调用 Windows API [英] Call Windows API from node.js msg
本文介绍了从 node.js msg 调用 Windows API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Node 的新手,我有这个简单的 Node.js 服务器在 Windows 上运行
I am new at Node, I have this simple Node.js server works on windows
服务器代码
var ws = require("websocket-server");
var server = ws.createServer();
server.addListener("connection", function(client){
console.log("new connection");
client.send("aaaaaa");
client.addListener("message", function(msg){
console.log(msg);
});
});
server.listen(8080);
我只想调用 Windows API insted 行
I just want to call windows API insted of line
console.log(msg);
不使用外部库有什么方法可以做到这一点
is there any way to do this without using external library
有什么想法吗?
推荐答案
我认为 node-ffi 可以帮助您做到这一点.node-ffi
提供加载和调用动态库的功能.使用 node-ffi
,您可以访问 user32
(例如)lib 并从 node.js 调用它们的函数.
I think node-ffi can help you to do that. node-ffi
provides functionality for loading and calling dynamic libraries. With node-ffi
you can get access to user32
(for example) lib and call their functions from node.js.
var FFI = require('node-ffi');
function TEXT(text){
return new Buffer(text, 'ucs2').toString('binary');
}
var user32 = new FFI.Library('user32', {
'MessageBoxW': [
'int32', [ 'int32', 'string', 'string', 'int32' ]
]
});
var OK_or_Cancel = user32.MessageBoxW(
0, TEXT('I am Node.JS!'), TEXT('Hello, World!'), 1
);
这篇关于从 node.js msg 调用 Windows API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文