我完全不熟悉Node JS和Electron。我正在嘗試使用Electron和Node JS將C++與HTML集成。我已經通過一些例子給出了:GIT電子調用節點本機擴展(C++)
我想要做的是從我的網頁的JavaScript電子加載調用本機函數(你好())。我使用node-gyp configure
來生成我的Visual Studio解決方案文件。 (.sln)。後來我用Visual Studio 2013 Express編譯了我的代碼,它在build \ Release文件夾中成功生成了我的.node文件。
這是我的index.js文件:
var addon = require('./build/Release/hello.node');
console.log(addon.hello());
時,我只需用node index.js
運行它,它給我所需要的輸出:
world
但問題帶有當我使用電子。我使用電子二進制(32位)來運行我的網頁。
以下是我main.js文件:
var app = require('app'); // Module to control application life.
var BrowserWindow = require('browser-window'); // Module to create native browser window.
require('crash-reporter').start();
var mainWindow = null;
// Quit when all windows are closed.
app.on('window-all-closed', function() {
if (process.platform != 'darwin') {
app.quit();
}
});
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
mainWindow = new BrowserWindow({width: 1366, height: 768});
mainWindow.loadUrl("file://" + __dirname + "/HtmlFile/index.html");
mainWindow.on('closed', function() {
mainWindow = null;
});
});
現在,這是我的JavaScript在那裏我調用本地插件:
//************* My Functional logic **************
//************************************************
var addon = require('../build/Release/hello');
alert(addon.hello());
當我運行這個或加載此我收到以下錯誤:
Uncaught Error: %1 is not a valid Win32 application. ATOM_SHELL_ASAR.js:137
C:\Users\Administrator\Desktop\MyAPP\build\Release\hello.node
正在關注是我package.json
:
{
"name": "MyAPP",
"version": "1.0.0",
"description": "Desc",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"nan": "^2.0.9"
},
"gypfile": true
}
這是我binding.gyp
:
{
"targets": [
{
"target_name": "hello",
"sources": [ "hello.cc" ],
"include_dirs": [
"<!(node -e \"require('nan')\")"
]
}
]
}
我使用'--arch = ia32'標誌時運行到同一個問題來設置當我使用' - arch = x64' flag收到'Uncaught Error:系統無法在%2的消息文件中找到消息號爲0x%1的消息文本。'但是,如果我用'node。/'運行該命令,則會打印出「world 「到預期的命令行,同樣的代碼在電子MacOS上工作,所以似乎是一個基於Windows電子的問題 – devonbleibtrey