Electronにて、Dllを読み込ませたく(最終的にはfelicaのDllを読み込ませたい)、ffiをインストールし試行錯誤しながらffiのリビルドまでたどり着いたのですが、
下記のようなエラーが発生し行き詰っております。
Uncaught Error: Dynamic Linking Error: Win32 error 193
尚、Dllのビルドは32bit,64bit両方で試してみました。
解決策を御教授願います。
下記、設定とソースコードを記載いたします。
環境 Windows10 64bit node 8.10.0(64bit版) npm 6.10.2 electron 1.4.13
設定 npm ini npm install electron --save-dev npm install electron-rebuild npm install ref npm install https://github.com/node-ffi/node-ffi.git ./node_modules/.bin/electron-rebuild
※ffiのリビルドを通すために試行錯誤したため上記と同じ方法で通るかは不明です。
Dll1.h
C++
1#pragma once 2 3#include <iostream> 4 5extern "C" __declspec(dllexport) const char * HelloWorld();
Dll1.cpp
C++
1#include "stdafx.h" 2#include "Dll1.h" 3 4const char * HelloWorld() 5{ 6 const char *cstring = "Hello, World!"; 7 return cstring; 8}
※C++の知識はないため、ネットよりひらってきました。
index.js
javascript
1const {app, BrowserWindow} = require('electron') 2 3let win 4 5app.on('ready', () => { 6 win = new BrowserWindow({width: 800, height: 600}) 7win.webContents.openDevTools(); 8 win.loadURL('file://' + __dirname + '/index.html') 9 10 win.on('closed', () => { 11 win = null 12 }) 13}) 14 15app.on('window-all-closed', () => { 16 if (process.platform !== 'darwin') { 17 app.quit() 18 } 19}) 20 21app.on('activate', () => { 22 if (win === null) { 23 createWindow() 24 } 25})
index.html
html
1<!DOCTYPE html> 2<html> 3<head> 4 <meta charset="UTF-8"> 5 <title>DLL呼び出しサンプル</title> 6</head> 7<body> 8 <script> 9 var ffi = require('ffi'); 10 11 var dllSamplePath = "Dll1.dll"; 12 var dllSample = ffi.Library(dllSamplePath, { 13 'HelloWorld': ['string', []] 14 }); 15 16 var result = dllSample.HelloWorld(); 17 alert(result); 18 </script> 19</body> 20</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。