I am completely new to Node JS and Electron. I am trying to integrate C ++ with HTML using Electron and Node JS. I gave some examples below: GIT
What I'm trying to do is call the native (hello ()) function from my javascript webpage, which is electronically loaded. I used node-gyp configure to create my Visual Studio solution file. ( .sln ). And later, I compiled my code using Visual Studio 2013 Express, which successfully generated my .node file in the \ Release Folder assembly.
This is my index.js file:
var addon = require('./build/Release/hello.node'); console.log(addon.hello());
when I just run this using node index.js it gives me the desired result:
world
But the problem arises when I use Electron. I am using an electronic binary (32 bit) to launch my web page.
Below is my main.js file:
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; }); });
Now this is my javascript where I call my own addon:
//************* My Functional logic ************** //************************************************ var addon = require('../build/Release/hello'); alert(addon.hello());
When I run this or load this page, I get the following error:
Uncaught Error: %1 is not a valid Win32 application. ATOM_SHELL_ASAR.js:137 C:\Users\Administrator\Desktop\MyAPP\build\Release\hello.node
Below is my 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 }
This is my binding.gyp :
{ "targets": [ { "target_name": "hello", "sources": [ "hello.cc" ], "include_dirs": [ "<!(node -e \"require('nan')\")" ] } ] }