用于C ++ DLL的unity3d插件中的DllNotFoundException [英] DllNotFoundException in unity3d plugin for c++ dll
问题描述
我正在研究Unity Plugin项目,并尝试从c#文件导入c ++本机dll. 但是我一直在获取dllnotfoundexception.
c ++ dll代码:
extern "C" {
extern __declspec( dllexport ) bool IGP_IsActivated();
}
c#代码:
[DllImport("mydll")]
private static extern bool IGP_IsActivated();
Dll到位并且文件存在.正常工作.所有依赖的dll都存在于相同的层次结构中,但我仍然会遇到dllnotfound异常.
任何帮助,万分感谢!
感谢此
将 使用此脚本,无需在DLL周围进行复制. Unity编辑器在 I am working on the Unity Plugin project and try to import the c++ native dll from c# file.
But I keep getting dllnotfoundexception. c++ dll code: c# code: Dll is in place and FIle.Exists work properly. All dependent dlls are present at same hierarchy, but I still end up in dllnotfound exception. Any help, much appreciated!! Thanks to this Unity forum post I came up with a nice solution which modifies the Put the following static constructor into a class which uses the plugin: Add With this script there is no need to copy around DLLs. The Unity editor finds them in the 这篇关于用于C ++ DLL的unity3d插件中的DllNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋![InitializeOnLoad]
添加到类中,以确保构造函数为在编辑器上运行发射: [InitializeOnLoad]
public class MyClassWhichUsesPlugin
{
...
static MyClassWhichUsesPlugin() // static Constructor
{
...
}
}
Assets/.../Plugins/...
文件夹中找到它们,而可执行文件在..._Data/Plugins
-目录中找到它们(构建时会在其中自动复制它们).extern "C" {
extern __declspec( dllexport ) bool IGP_IsActivated();
}
[DllImport("mydll")]
private static extern bool IGP_IsActivated();
PATH
-environment variable at runtime:
Project\Assets\Wherever\Works\Best\Plugins
.static MyClassWhichUsesPlugin() // static Constructor
{
var currentPath = Environment.GetEnvironmentVariable("PATH",
EnvironmentVariableTarget.Process);
#if UNITY_EDITOR_32
var dllPath = Application.dataPath
+ Path.DirectorySeparatorChar + "SomePath"
+ Path.DirectorySeparatorChar + "Plugins"
+ Path.DirectorySeparatorChar + "x86";
#elif UNITY_EDITOR_64
var dllPath = Application.dataPath
+ Path.DirectorySeparatorChar + "SomePath"
+ Path.DirectorySeparatorChar + "Plugins"
+ Path.DirectorySeparatorChar + "x86_64";
#else // Player
var dllPath = Application.dataPath
+ Path.DirectorySeparatorChar + "Plugins";
#endif
if (currentPath != null && currentPath.Contains(dllPath) == false)
Environment.SetEnvironmentVariable("PATH", currentPath + Path.PathSeparator
+ dllPath, EnvironmentVariableTarget.Process);
}
[InitializeOnLoad]
to the class to make sure that the constructor is run at editor launch: [InitializeOnLoad]
public class MyClassWhichUsesPlugin
{
...
static MyClassWhichUsesPlugin() // static Constructor
{
...
}
}
Assets/.../Plugins/...
-folder and the executable finds them in ..._Data/Plugins
-directory (where they get automatically copied when building).