dll loading in editor on windows

I wrote a c++ plugin, that does some stuff with fmod. The plugin itself seems to work just fine, and I can use it in a Windows standalone build when i copy the fmodex.dll next to the executable. However if I run the game in the editor I always get a DllNotFoundException. My understanding of dll's on windows is, that windows will look up the dll in the system32 folder (XP), then in the application folder and the current working directory. So I printed out the current working directory, which - no surprise - is the projects root folder. However, copying the fmodex.dll to that folder doesn't get rid of the Exception.

I have another project where I did something very similar (only with another dll) and this works. So any ideas what could go wrong here?

At least on the Mac, you are supposed to create a folder titled 'Plugins' inside the project view (assets directory). All plugin DLLs are to reside within that folder.

Try the same thing on windows.

From Unity Manual on Plugins

and an excerpt:

Once you have built your bundle you have to copy it to Assets->Plugins folder. Unity will then find it by its name when you define a function like this:

[DllImport ("PluginName")]
private static extern float FooPluginFunction ();

Please note that PluginName should not include the extension of the filename. Be aware that whenever you change code in the Plugin you will have to recompile scripts in your project or else the plugin will not have the latest compiled code.

I think I finally have a clue what's going on. Since Unity2.6 switched to use fmod as audio core (which is a great idea!) there is a "fmodex.dll" in the edior application directory. Since my plugin was probably built using a different version of the fmodex lib it seems to find the one in the app directory and tries to load that. But since they are different versions the loader is not satisfied and I get the DllNotFoundException. At least that's what I think is going on.

I got the same problem here when trying to load FModEx.dll + FMod_Event.dll in the Editor (build works fine).

The conclusion I got was that unity editor's FModEx.dll (the one unity uses since 2.61) is causing "Dll Hell" as the editor process binds it's own dll, we can't load our version. FMod_Event.dll has a dependency on FModEx.dll but it does not reconize unity's version. The result is that you get a "DllNotFoundException" when FMod_Event tries to find FModEx.

The solution I found was renaming my version, not unity's, of FModEx.dll to FModE2.dll and changing every occurrence of that name inside both dlls, Ex and Event, with a HexEditor. Now everything works fine. :-D

When building for Mac you will probably have to make your wrapper point towards the regular Dylibs. Somehtin like this:

    public class VERSION
{
    public const int    number = 0x00042808;

#if MAC

    public const string dll    = "libfmodex.dylib";

#else

    public const string dll    = "fmode2.dll";

#endif

}

[Removed Answer]