Search Unity

Chain of dependency dll's not loading correctly.

Discussion in 'Editor & General Support' started by Davelis4, Sep 23, 2017.

  1. Davelis4

    Davelis4

    Joined:
    May 1, 2014
    Posts:
    7
    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.)

    Code (CSharp):
    1. [DllImport(dllName: "Story", CallingConvention = CallingConvention.Cdecl)]
    2. 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.
     
  2. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    If you LoadLibrary a DLL and never unload it, then it will never be automatically unloaded (until you restart the editor). Every subsequent LoadLibrary will return the same already loaded DLL. So maybe that's happening and you have an old version of your DLL without the functions that you expect to be there. You can explicitly call FreeLibrary say in OnApplicationQuit.

    You could also double check exactly what DLL is actually being loaded. You should be able to use Process Monitor to monitor Unity.exe and filter on the "Load Image" operation. You should see your library get loaded.

    -sam
     
  3. Davelis4

    Davelis4

    Joined:
    May 1, 2014
    Posts:
    7
    Hey,

    DLL A is being loaded but A cannot get B dll's functions with GetProcAddress whilst, B is also being loaded.

    Any insight on that?
     
  4. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Yeah:
    • Did you try restarting Unity just to check that it wasn't an old library that was still loaded that didn't have those functions?
    • Did you try using Process Monitor to verify that the DLL being loaded is the one you expect (i.e. check the path)?
    It sounds to me like the wrong DLLs are being loaded. If GetProcAddress works outside of Unity it should work inside Unity.

    -sam