electron之坑addon

dll 错误

Error: A dynamic link library (DLL) initialization routine failed

依赖的dll未放入目录也会导致模块加载失败

Error: The specified module could not be found.

node.exe 未延迟加载

需要配置下面俩项

#ifdef _MSC_VER

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#include <windows.h>
#include <delayimp.h>
#include <string.h>

static FARPROC WINAPI load_exe_hook(unsigned int event, DelayLoadInfo *info) {
	HMODULE m;
	if (event != dliNotePreLoadLibrary)
		return NULL;

	if (_stricmp(info->szDll, "NODE.EXE") != 0)
		return NULL;

	m = GetModuleHandle(NULL);
	return (FARPROC)m;
}

decltype(__pfnDliNotifyHook2) __pfnDliNotifyHook2 = load_exe_hook;

#endif

在这里插入图片描述

node.lib 同函数名依赖顺序问题

查看node.lib导出函数,主要有
uv
openssl
v8
zlib

dumpbin  /LINKERMEMBER node.lib >nodelib.txt

修改node.lib为最后依赖

node gyp找不到vs

2017版本后依赖powershell脚本

$ExecutionContext.SessionState.LanguageMode 看看是不是为 FullLanguage

__PSLockdownPolicy 系统环境变量 为 1,如果为4为 ConstrainedLanguage。

另外说明我设置 npm config set msvs_version 2019 无效

二进制文件坑

git 默认换行符自动转换,导致二进制文件失效

关闭转换

git config --global core.autocrlf false

依赖非n-api库比如openssl,uv

文档

cd /path-to-module/
HOME=~/.electron-gyp node-gyp rebuild --target=1.2.3 --arch=x64 --dist-url=https://electronjs.org/headers

只使用 #include <node_api.h> 保证跨版本兼容性

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骇客之技术

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值