記錄踩的坑,防止之後忘記html
1. 須要用window電腦
2. npm容易出錯,建議使用cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
3. 若是dll是32位的nodejs和electron都要使用對應的版本纔可使用,
4. nodejs版本建議9版本如下
複製代碼
// 首先安裝 node-gyp
1. cnpm install node-gyp -g
// 拉取electron-vue項目
2. vue init simulatedgreg/electron-vue my-project
// 這裏我是將electron的版本改爲了1.8.2在進行安裝,在這個版本測試穩定,其餘的沒測試
cd my-project cnpm install
複製代碼
cnpm install --global --production windows-build-tools
複製代碼
1. cnpm install node-ffi
複製代碼
分別到 ref和ffi執行下面命令
cd .\node_modules\ref\ 和 cd .\node_modules\ffi\
執行
node-gyp rebuild --arch=ia32 --dist-url=https://atom.io/download/atom-shell --runtime=electron --target=1.8.2
複製代碼
--arch=ia32 : ia32表示32位,64位請改爲x64,--target=1.8.2 與上面安裝的electron版本一致vue
出現 生成代碼
字樣表示成功node
1. cnpm install -g electron-builder
// 在項目目錄下執行
2. electron-builder install-app-deps
複製代碼
# Electron 的版本。
set npm config --target=1.8.2
# Electron 的系統架構, 值爲 ia32 或者 x64。
set npm config --arch=ia32
# 下載 Electron 的 headers。
set npm config --disturl=https://npm.taobao.org/mirrors/atom/
# 告訴 node-pre-gyp 咱們是在爲 Electron 生成模塊。
set npm config --runtime=electron
複製代碼
const ffi = require('ffi')
const iconv = require('iconv-lite')
const Dll =new ffi.Library('dll\\fzyktclient.dll', {
// 第一個參數爲返回值,第二個參數
add: ['int', ['int','int', 'string']],
})
const resBuffer= Buffer.alloc(1024);
const res=Dll.add(1,2,resBuffer)// 3
// 返回值,0表明成功
if(res===0){
// resBuffer 返回的提示信息
// 解決返回中文亂碼問題
const data= const data=iconv.decode(resBuffer, 'GBK');
console.log(data)// 操做成功
}
複製代碼
Q:python
error msb4019:未找到導入的項目「C:\Program Files (x86 )\MSBuild\
Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Default.props」
複製代碼
A:shell
// 在命令行執行改命令便可,2017 是你當前vs對應的版本,好比你裝的是2015版本,就改爲2015
npm config set msvs_version 2017
複製代碼
Q:npm
Uncaught Error: Dynamic Linking Error: Win32 error 126
複製代碼
A:windows
Dll引用的路徑不對,檢查路徑是否書寫正確,須要用絕對路徑
複製代碼
Q:bash
Uncaught Error: Dynamic Linking Error: Win32 error 193
複製代碼
A:架構
dll 位數不對應,例如electron/nodejs是32位的dll是64位的
複製代碼
Q:app
Uncaught Error: Dynamic Linking Error: Win32 error 127
複製代碼
A:
DLL中沒有找到對應名稱的函數,須要檢查頭文件定義的函數名是否與DLL調用時寫的函數名是否相同。
Dll錯誤,檢查你的dll文件是否還引用了其餘的資源及dll文件
複製代碼
Q:
Uncaught Error: Dynamic Linking Error: Win32 error 1114
複製代碼
A:
dll初始化失敗,通常是在打包成exe文件發生,多是你的dll在打包後的位置不正確,
程序調用不到就會去系統c盤找對應的dll文件
複製代碼
Q:
fatail error LNK1127
複製代碼
A:
刪除用戶目錄下.node-gyp 從新安裝 npm install node-gyp -g
複製代碼
Q:
調用dll中文亂碼問題
複製代碼
A:
// 安裝iconv-lite
1.cnpm install iconv-lite -D
2.let iconv = require('iconv-lite')
3.iconv.decode(obj, 'GBK') // 解碼成utf8.
複製代碼
Q:
打包成exe時出現
The process cannot access the file because it is being used by another process
複製代碼
A:
緣由是程序被佔用,刪掉build李敏啊除icons外的文件,從新執行編譯,若是還不是,則關閉編輯工具
好比vscode也會佔用,而後在命令行從新編譯便可
複製代碼
Q:
npm run build 下載包失敗
複製代碼
A: