C/C++DLL库导入unity失败

问题遇到的现象和发生背景

unity导入C/C++DLL库后,库内函数无法引用,且报错。

用代码块功能插入代码,请勿粘贴截图
运行结果及报错内容

Failed to load 'Assets/Plugins/******

//Failed to load 'Assets/Plugins/******.dll', expected x64 architecture, but was x86 architecture. You must recompile your plugin for x64 architecture.
//DllNotFoundException: ******.dll assembly: type: member:(null)
[DllImport("SWHidApi.dll")]
   public static extern void SWHid_DllInt();

img

img

我的解答思路和尝试过的方法

由于是C/C++代码写的库,不是.Net框架下的库,难以找到工具打开后重新编译。
将Dllmport的内容改成"SWHidApi"就是把.dll去掉后也不行。
自己写的动态库可以成功导入unity中并使用。

我想要达到的结果

把库成功导入unity内并使用

可以看看,希望对你有所帮助
https://blog.csdn.net/qq_36251561/article/details/127408607

建议:下载一个Dependency Walker【PE模块依赖分析工具】,打开软件中你需要的库【Assets/Plugins/******.dll】拷贝到系统目录或者特定的目录下就可以

该工具下载和使用方法链接:https://www.jb51.net/softjc/388532.html

你加载的SWHidApi.dll是32位dll,而你的unity是64位程序。所以会报“expected x64 architecture, but was x86 architecture”这样的错误。
解决办法:unity工程中cpu选择x86进行编译

解决一下报错就行了呀,你这个库是x64的,但是你编辑器选择是x86的,你改成x64的

img