<div>Here's what I'm struggling with (as best as I can understand it):</div>
<div> </div>
<div>I'm writing a program that uses functionality from two different sets of cdlls which reside in two different directories, call them 'libA.dll' and 'libB.dll'. Although I don't directly use it, both directories contain a dll with the same name, although they aren't in fact identical. Call them, "libC.dll". However, the c-functions I call from the clls I do use seem to implicitly use "libC.dll". The problem that occurs is that after I load one dll and call functions in it, when I try to load the second dll I get windows errors because the second dll tries to call a function in its version of libC.dll, but it finds the version meant for libB.dll, which doesn't contain that function.</div>
<div> </div>
<div>Oy, I hope some sample code makes it clearer:</div>
<div> </div>
<div>
<p><font face="courier new,monospace">def demo():</font></p>
<p><font face="courier new,monospace"> A = ctypes.cdll.LoadLibrary('/path1/libA.dll')<br> A.foo() # implicitly uses '/path1/libC.dll'<br> <br> _ctypes.FreeLibrary(A._handle)<br> <br> # CRASH! "The procedure entry point some_func could not be located<br>
# in the dynamic link library libC.dll.":<br> B = ctypes.cdll.LoadLibrary('/path2/libB.dll')</font></p>
<p><font face="courier new,monospace"> # libB.dll wants to use code from '/path2/libC.dll', but <br> # instead it finds '/path1/libC.dll' already loaded <br> # in memory, which doesn't<br>
# contain the function call it wants.</font></p></div>
<div> </div>
<div>Assuming my understanding of things is correct, then I believe what I need to do is to remove /path1/libC.dll from memory before I try loading libB.dll, but I haven't found any way of doing that. Can anyone offer my some suggestions?</div>
<div> </div>
<div> </div>
<div>Notes: </div>
<div>* the two sets of dlls are supplied by a vendor for working with its COTS packages; I don't have any control over the dll names used or the code therein. </div>
<div>* If I leave out the call to A.foo(), then I don't crash, but if I leave out the FreeLibrary call as well then I do crash.</div>
<div>* I've tried manipulating the PATH before loading the dlls, to no effect.</div>
<div>* I've tried del'ing A and running gc.collect() before loading B. </div>