1、32位的 .dll 無法在64位的unity編輯器下運行。
System.DllNotFoundException: xxx , 64位的程序運行32位的dll是會報這種錯
2、Failed to load 'Assets/Plugins/xxx.dll', expected x64 architecture, but was x86 architecture. You must recompile your plugin for x64 architecture.
將CPU選擇.dll對應的CPU
3、System.EntryPointNotFoundException:Unable to find an entry point
原因就是:c++源代碼中的函數在編譯成DLL后,函數的名稱就發生了改變:會在函數的前后產生一些字符。所以找不到方法的入口點。
[DllImport(dllName, EntryPoint = "?Free@@YAHXZ")] private static extern int Free();
Free的名字編譯為dll時,變成了 ?Free@@YAHXZ ,猜想可能的原因是直接寫的C++接口,而不是C接口
即,可能是沒有通過 extern "C" int _DLLExport Free(); 的形式封裝。
也可再強制一下編碼格式 CharSet = CharSet.Unicode
即,
[DllImport(dllName, EntryPoint = "?Free@@YAHXZ",CharSet = CharSet.Unicode)] private static extern int Free();
附:eXeScope是查看 dll、exe等編譯后的名字的小工具,很好用,下載地址:https://download.csdn.net/download/jasonczy/10657046
在導出里就可以看到對應的名字了。