- Home /
Chain of dependency dll's not loading correctly.
Hey,
I have 3 dlls A,B and C which I am trying to use from Unity but I am having an issue.
DLL A depends on B and B depends on C. The linking is run-time so A uses LoadLibrary for B and B does the same for C also the dlls use GetProcAddress to load specific functions from each dll.
When I test those 3 dll's outside of Unity in a test project, everything seems to be working fine, whilst, when I import them to Unity the following happens:
First, Unity Loads A dll's functions (e.g.)
[DllImport(dllName: "Story", CallingConvention = CallingConvention.Cdecl)] public static extern bool release();
Afterwards dll A tries to load dll's B functions. While LoadLibrary(B) works on A (doesn't return NULL), GetProcAddress(Bfunction) fails with error code 127 and thus A cannot load B functions from Unity.
As I mentioned earlier, the same setup works outside of Unity.
Any logic or reasoning behind this? Even better, any solutions to this matter?
Thanks in advance.
Answer by xastec · Jan 04, 2018 at 10:45 AM
Hi Davelis4,
I have met same issues, that a native plugin DLL A, depends on DLL B and B depends on DLL C. Calling from Unity a DLL A function, which calls DLL B functions results in load failure. I have no source code of DLL B and C, they return me message "Library is not loaded" and an exception, so I assume the same issue as yours.
So far I have found two workarounds to get rid of this issue:
1, converting my DLL A to a executable application, and making another simpler DLL D to communicate between Unity and the executable. Due to my use case, this approach is acceptable. However this introduces more work and is less user friendly.
2, copying DLL B and DLLC to the "Editor" folder, where Unity.exe locates. Then calling DLL A has no problems. This approach is ugly for installation.
Hopefully, Unity could make our life easier.
Thanks.
PS: Using "Dependency Walker" with DLL A, I can see B and C are not on the list. I don't know if this is why Unity can not load DLL B and DLL C. However, for dynamic loaded DLLs, how can we add them to the list ? If the 3rd party lib providers chose to dynamic load their dependencies, what else we could do?
Your answer
Follow this Question
Related Questions
Connect matlab and unity 0 Answers
Converting from c# string to c++ string 1 Answer
Failed to load DLL with error "The specified module cannot be found." 1 Answer
Shared memory between c# and c++ 1 Answer
Importing C++/CLI DLL causes errors 0 Answers