- Home /
fmodex.dll linkage trouble
I built a plugin that depends on fmodex.dll. The plugin itself works and I can use it in a standalone unity build. It doesn't work in the editor. I think that's because the editor itself has a dependency on fmodex.dll. So my plugin finds the fmodex.dll in the editors application folder. This doesn't work, because I compiled and linked against a different fmod version. So two questions:
- Is there a way to force the plugin to use the correct fmodex.dll?
- If that's not possible could someone tell me which version of fmod i have to link against? The version on the editors dll says it's 4.26.0, but i downloaded that version from the fmod site and the dll's file sizes don't match, so it seems to be some kind of special unity build. Or I'm just stupid, that's entirely possible. ;)
Answer by StephanK · Feb 07, 2010 at 12:57 PM
I now have a workaround for this problem. Although it would be a much nicer and cleaner solution if Unity would rely on an official released fmodex.dll.
The workaround is to delayLoad the fmodex.dll from your own dll. To do this you need to set a special linker option when building your dll. This alone won't save you, it will still throw the exception the first time you make a call to an fmod function.
To prevent that you have to specify a "delayHook" (http://msdn.microsoft.com/en-us/library/f0fkfy9y.aspx). In our case we only need to handle the "dliNotePreLoadLibrary" case and reroute the call to fmodex.dll to someothername.dll. Now we can include a renamed fmodex.dll (using the specific release that you linked your dll against) in our project root folder. When we start the editor it will try to load fmodex.dll the first time we make a call to any fmod function. Instead trying to load the unity fmodex.dll it will now load the correct dll. Here's the example code for the delayHook function.
FARPROC WINAPI delayHook( unsigned dliNotify, PDelayLoadInfo pdli ) { switch( dliNotify ) { case dliNotePreLoadLibrary: if( strcmp( pdli->szDll, "fmodex.dll" ) == 0 ) return (FARPROC)LoadLibrary( "fmodex2.dll" ); break; default: return NULL; }
return NULL; }
To actually use this hook you have to include this line of code on a global scope within your dll:
PfnDliHook __pfnDliNotifyHook2 = delayHook;
I hope this helps someone with a similar problem, as it took me way too long to figure this out...
Answer by Sren Christiansen · Jan 27, 2010 at 09:08 AM
Can you describe "not working" in more detail? (Unity won't start? crashes? ) Unity is using a custom build of fmod (based on 4.26), so using another vanilla (even 4.26) version of fmod could lead to a undefined behaviour. But if your not using AudioSource/Clips at all and only fmod::channels/sounds you should be fine (using 4.26). But again, I need some more details on the specific errors.
What happens is that when I try to call/import methods from my dll while running in the editor it will throw a DllNotFoundException. It does find my dll, but it seems to fail to load the fmodex.dll. I suspect this is because my dll is searching for a specific version of the dll (the one it was linked against) and finds the unity specific fmodex.dll first because it is in the executables path. (unity/editor) If I run the game in standalone mode it works because there is no conflicting fmodex.dll.
Answer by JC · Feb 11, 2010 at 11:11 AM
I had the same problem and solved it by renaming my version of FModEx.dll to FModE2.dll and changing every occurrence of that name inside both dlls, Ex and Event, with a Hex Editor.
A better description of this answer is also on this link:
http://answers.unity3d.com/questions/2786/dll-loading-in-editor-on-windows/3920#3920
Answer by seventyfive · Apr 19, 2010 at 01:10 PM
Just stumbled upon this problem, too.
Is there a better solution than using two different FMOD builds at once?
Even if the internal verison is custom built: Is the internal FMOD not fully accessible?
You might be able to dllimport the functions you need from the internal dll, but you'd have to wrap the dll declaring structs and classes in you c# code, which is apita. There is a F$$anonymous$$OD unity wrapper somewhere around (squaretangle.com if i remember correctly), but that was built to work with another fmod version. $$anonymous$$aybe you could just remove the corresponding check from the wrapper and it will work unless there were some major changes between versions. For me this wasn't an option as I wanted to do all F$$anonymous$$OD and audio stuff in unmanaged(C++) code for performance reasons.
I just aswered your comment in the other post.
http://answers.unity3d.com/questions/2786/dll-loading-in-editor-on-windows/3920#3920
That's exactly my problem, as even if I can handle the second version I am running with two separate engines. Squaretangles solution I tried already without success but will give JCs hint a go. $$anonymous$$aybe I should just wait for the 3.0 version, hope its co$$anonymous$$g soon...
Your answer
![](https://koobas.hobune.stream/wayback/20220612002022im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
nonstatic extern functions from DLL plugin import 1 Answer
Cant link PLUGIN.DLL with PLUGIN-EDITOR.DLL 1 Answer
Unity plugins 0 Answers
Referencing a DLL in C# 0 Answers
How can I access frame data using C# from the NatNetML.dll 0 Answers