Hello,
I'm having trouble with a dll. It crashes(freeze) on the second test. This is probably because the dll cannot be loaded twice (it communicates with drivers), and Unity does not unload when I stop testing.
I found this command:
FreeLibrary(GetModuleHandle("TestDll"));
but it gives this error:
Assets/TestScript.cs(76,17): error CS0103: The name `FreeLibrary' does not exist in the current context
Does anyone have an idea how I can use FreeLibrary, because I can't find the dependency for it.
I'm using Unity 3.1 with Windows 7.
Thanks :)
Siewart
I do not believe that such a function exists in mono as it is not cross-platform and I can find no such function with the API. According to MSDN, FreeLibrary is a function defined in Winbase.h. I'm pretty sure you cannot or should not be trying to use it in this context.
I feel that you are correct in that your dll usage is likely failing to release certain needed resources, but I am not certain if it is because the dll is not unloaded although it may well be the case. I know that I find it frustrating to be working on a dll and to have to restart Unity in order to remove the write protection placed on the dll if I ever run my game from the editor. This write protection indicates that Unity still has the dll loaded and depending on what that entails, it may be driving your problem but, in my experience, every time a dll I was using in Unity crashed, it was my own fault rather than some resources being tied up by having the dll loaded.
Did you consider that perhaps your dll is either doing something erroneous or being used erroneously? Are you using threading and when you stop execution, do you ensure that all threads are terminated first? Do you allocate any resources that you don't free up? Without more details on the dll and its usage, I can only guess at what might be wrong in the event that it is not because the dll is still loaded.