I’m using a 3rd party DLL written in unmanaged C++ that controls some hardware we have.
Unfortunately this DLL crashes now and then and I’ve been tasked to make it ‘reload’ automagically. I’m not too sure about how to proceed to get best results.
My project uses C++.Net 2.0 (2005). I’m wrapping the 3rd party stuff in a separate DLL. I’ve been trying to FreeLibrary() and LoadLibrary(). However when I FreeLibrary(), some internal DLL dependencies remain allocated and LoadLibrary() will make it crash because of corrupted memory.
Another approach that was suggested was to refactor the whole project using .NET remoting interfaces. It would make it easier to kill another process and restart it but it will be a lot of work.
Any suggestions? Pointers? Hints?
The most effective approach will be to not load that DLL in your application’s process at all. Instead, create a second process whose only job is to use that DLL on behalf of your application. You can use a shared memory region, local socket, or other IPC mechanism to control the proxy process.
This way, when the problematic DLL crashes, you can simply allow the proxy process to die without worrying about the (nearly impossible) task of trying to make sure the DLL didn’t corrupt anything important on its way down. Your main process need only start a new instance of the proxy process and carry on.