可以使用c++作为Electron.js的后端吗?

ryoqjall  于 9个月前  发布在  Electron
关注(0)|答案(1)|浏览(91)

我有一个任务,使简单的c应用程序存储到二进制文件的信息,然后需要与此信息,如编辑,删除,读取简单的操作。我想使用Electron创建桌面应用程序来设计UI,并使用c来处理信息。
有可能吗?如何将C++包含在Electron中?

hsgswve4

hsgswve41#

Electron使用的是nodejs,所以你仍然可以将cpp代码打包成一个node模块,然后在你的electron应用程序中将其作为依赖项使用。
请参阅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

相关问题