[python-win32] ctypes question DLL

Tim Golden mail at timgolden.me.uk
Tue Jul 8 11:41:17 CEST 2008


Marcus Low wrote:
> Hi,
> I have been reading the documentation on ctypes and the 2.5 python on 
> ctypes when it comes to loading libraries.
> 
> But surprisingly, or maybe i miss it somewhere, but How do you unload 
> the loaded dll?
> 
> For eg : dllfunc = ctypes.CDLL("mylib.dll")
> 
> Later if i want to replace this dll without stopping the python program 
> and reload the dll, how can this  be done?

I imagine this isn't such a common requirement, because
the FreeLibrary function is present in _ctypes but isn't
exposed via ctypes.

<code - untested>
import ctypes
import _ctypes

dllfunc = ctypes.CDLL("mylib.dll")
_ctypes.FreeLibrary (dllfunc._handle)

</code>


TJG


More information about the python-win32 mailing list