2017-04-13 23 views
2

我有一个任务,使简单的C++应用程序存储信息到二进制文件,然后需要使用此信息进行简单的操作,如编辑,删除,阅读。 我想创建使用Electron的桌面应用程序来设计用户界面,并使用C++进行信息操作。是否有可能使用C++作为Electron.js的后端?

是否有可能以及如何将C++包含到电子中,是否有任何教程? 在此先感谢。

回答

3

电子正在使用nodejs,因此您仍然可以将cpp代码打包为节点模块,然后在您的电子应用程序中将它用作依赖项。

看到Hello World示例here基本上做到这一点:

module.exports.hello =() => 'world'; 

这是从他们的教程中的例子:

// hello.cc 
#include <node.h> 

namespace demo { 

using v8::FunctionCallbackInfo; 
using v8::Isolate; 
using v8::Local; 
using v8::Object; 
using v8::String; 
using v8::Value; 

void Method(const FunctionCallbackInfo<Value>& args) { 
    Isolate* isolate = args.GetIsolate(); 
    args.GetReturnValue().Set(String::NewFromUtf8(isolate, "world")); 
} 

void init(Local<Object> exports) { 
    NODE_SET_METHOD(exports, "hello", Method); 
} 

NODE_MODULE(addon, init) 

} // namespace demo 
相关问题